QP School

Full Version: Break and Continue statements in C
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
break is used to exit the loop prematurely, while continue is used to skip the current iteration and proceed to the next.

for (int i = 1; i <= 10; i++) {
    if (i == 5) {
        break; // Exit the loop when i is 5
    }
    printf("%d ", i);
}
// Output: 1 2 3 4

for (int i = 1; i <= 5; i++) {
    if (i == 3) {
        continue; // Skip the iteration when i is 3
    }
    printf("%d ", i);
}
// Output: 1 2 4 5