For, While, and Do-While Loops
Loops allow repeating a block of code multiple times.
- For loop: Used when the number of iterations is known.
- While loop: Checks the condition before each iteration.
- Do-While loop: Executes the code block at least once.
for (int i = 0; i < 5; i++) {
cout << i;
}
int j = 0;
while (j < 5) {
cout << j;
j++;
}
do {
cout << j;
j++;
} while (j < 5);