QP School
Incorrect loop conditions 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: Incorrect loop conditions in C (/showthread.php?tid=5117)



Incorrect loop conditions in C - Qomplainerz - 07-26-2023

Using incorrect loop conditions can lead to infinite loops or incorrect program behavior.

// Incorrect
int i = 0;
while (i <= 5) {
    printf("%d ", i);
    // Missing increment of 'i' (i++ or i--)
}

// Correct
int i = 0;
while (i <= 5) {
    printf("%d ", i);
    i++;
}