@mmderbi
π C++ Programming β Part 6: Loops (For & While)
Sometimes you need your code to repeat tasks β like printing numbers or checking data π
Thatβs what loops do!
πΉ For Loop:
Used when you know how many times to repeat π
for (int i = 1; i <= 5; i++)
cout << i << endl;
β
Prints 1β5
πΉ While Loop:
Repeats until the condition is false π
int x = 1;
while (x <= 5) {
cout << x << endl;
x++;
}
πΉ Do-While:
Runs the code at least once π
int y = 1;
do {
cout << y << endl;
y++;
} while (y <= 5);
πΉ Why It Matters:
Loops save time, reduce code, and handle repetition automatically βοΈ
πΉ Coming next (Part 7):
Weβll learn arrays β how to store multiple values easily π§