Mahmoud Derbi pfp
Mahmoud Derbi

@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 🧠
3 replies
1 recast
6 reactions