2

I was revisiting some basic loop programs in preparation for an academic test.

int N=10;
for (int i=0; i<N; i++)
  {
    if (i==2) continue;
    printf("%d", i);
  }
int i=0;
while (i<N)
  {
    if (i==2) continue;
    printf("%d", i);
    i++;
  }

Both the loops are supposed to do the same thing, but the "while" version of it would fail since the continue causes the control to totally miss the increment ordered below itself.

But when I run the program, I just see the blinking cursor in the terminal window.

I expected at least the first loop to duly perform its duties and then the silent treatment from the terminal. But it seems to have a mind of its own. Does anyone have a good explanation?

halfer
  • 18,701
  • 13
  • 79
  • 158

0 Answers0