C continue statement
Created By: chatGPT
The continue statement in C is used within loops to skip the remaining statements in the current iteration and proceed to the next iteration. Specifically, when the continue statement is encountered, control jumps to the next loop iteration, bypassing any code that follows it in the loop's body. It's often used when a certain condition should lead to a quick skip of the rest of the loop's code for that particular iteration.
#include <stdio.h>
int main() {
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
continue; // Skip the even numbers
}
printf("%d ", i); // Only prints odd numbers
}
return 0;
}
In this example, we have a loop that iterates from 0 to 9. Inside the loop, we use an if condition to check if the current number is even. If it is, the continue statement is executed, skipping the printf function for that iteration, resulting in only odd numbers being printed.
Output:
1 3 5 7 9