07-26-2023, 07:08 AM
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++;
}
// 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++;
}