QP School

Full Version: Incorrect loop conditions in C
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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++;
}