Home > Net >  Why continue statement not execute the below lines of codes in infinite loop
Why continue statement not execute the below lines of codes in infinite loop

Time:09-02

#include<stdio.h>
int main()
{
 int i=0;
 for(;;)
 {
   if(i==10)
   {
     continue;
   }
   printf("%d",  i);
 } 
}

This above code makes the output as without print anything.But by my logic it prints the value from 1 to infinite times except 10.The continue statement doesn't run the below code after continue statement but the continue statement is inside the if condition then why it shouldn't run the statement that are below the continue statement?

CodePudding user response:

  1. The output of C-programs is normally buffered, which is likely the reason why you don't see anything. Try printf("%d\n", i) as the linefeed will flush the buffer.
  2. Once i reaches 10, the number will not be increased any more, so your expectation that "it prints the value from 1 to infinite times except 10" will not be met.
  • Related