Loop Control Statements in C Language
Loop control statements allow code to be executed repeatedly based on a condition. They are used to automate repetitive tasks.
🔹 1. for Loop
Used when the number of iterations is known.
for (int i = 1; i <= 5; i++) {
printf("%d\n", i);
}
🔹 2. while Loop
Used when the number of iterations is not known in advance; the condition is checked before the loop runs.
int i = 1;
while (i <= 5) {
printf("%d\n", i);
i++;
}
🔹 3. do-while Loop
The loop runs at least once, because the condition is checked after the body executes.
int i = 1;
do {
printf("%d\n", i);
i++;
} while (i <= 5);
🔹 4. break Statement
Used to exit the loop immediately.
for (int i = 1; i <= 10; i++) {
if (i == 5)
break;
printf("%d\n", i);
}
🔹 5. continue Statement
Skips the current iteration and proceeds to the next one.
for (int i = 1; i <= 5; i++) {
if (i == 3)
continue;
printf("%d\n", i);
}
🔹 6. goto Statement
Jumps to a labeled statement (not recommended in modern programming).
int i = 1;
start:
if (i <= 5) {
printf("%d\n", i);
i++;
goto start;
}
