Program with continue:
Code:
#include <stdio.h>
int n = 3;
int main() {
// loop from 1 to 5
for (int i = 0; i < 5; i++) {
// If i is equals to 3,
// continue to next iteration
// without printing
if (i == n)
{
printf("i ==6 \n");
continue;
}
printf("i \n");
}
return 0;
}
Output:
Program without continue:
Code:
#include <stdio.h>
int n = 3;
int main() {
// loop from 1 to 5
for (int i = 0; i < 5; i++) {
// If i is equals to 3,
// continue to next iteration
// without printing
if (i == n)
{
printf("i ==6 \n");
}
printf("i \n");
}
return 0;
}
Output:
As you can see, the outputs are different. Well, maybe you cannot see, but that's because you chose a terrible way of producing output such that you end up playing "spot the difference" rather than being able to see the difference at a glance. (Hint: the second output has an additional "i")
So, what's wrong with your thinking is that you thought it was a good idea to make things difficult for yourself instead of choosing to generate output that would be obviously different.