QP School
Break and Continue statements in C - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: C 18 Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=32)
+--- Thread: Break and Continue statements in C (/showthread.php?tid=5082)



Break and Continue statements in C - Qomplainerz - 07-25-2023

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