edited by
455 views
0 votes
0 votes

What is the out put of the following code,

i think it should be infinite loop, Correct me if iam wrong.

When i execute it, only it is printing "Hello" only one Time.

 

#include<stdio.h>      

int main()                                                                                                                                           
    {                                                                                                                                                    
    int i = 1;                                                                                                        
    do                                                                                                                                                       
        {                                                                                                                                                              
        printf("Hello\n");                                                                                                              
        continue;                                                                                                                                          
        i--;                                                                                                                                                           
        }while(i>=1);                                                                                                                            
    return 0;                                                                                                                                                  
}
edited by

2 Answers

1 votes
1 votes

#include<stdio.h>      
int main()                                                                                                                                           
{                                                                                                                                                    
int i = 1;                                                                                                        
do                                                                                                                                                       
{                                                                                                                                                              
printf("Hello\n");                                                                                                              
continue;        -------------------------------------------line:2                                                                                                                                  
i--;                                                                                                                                                           
}while(i>=1);     --------------------------------------- line:4                                                                                                                       
return 0;                                                                                                                                                  
}

yes, it will be infinite loop because , we know that do... while loop must at least  for 1 time. and line 2, continue statement is written, so whatever below continue statement will not be executed., each time when continue statement will hit, flow of execution of program will goes on start of do while loop.. Program is never going to be terminate because condition written line:4 never execute. So program will be in infinite loop.....

0 votes
0 votes
when you execute it , it does enter into infinite loop

U said it doesnt

Try it once properly

Related questions

1 votes
1 votes
1 answer
3
sambana asked Dec 20, 2018
3,055 views
Good Morning,I want to start Engineering Mathematics and need help from you to know where to start and what would be the best sequence to complete the whole subject?
0 votes
0 votes
0 answers
4
__ asked Feb 13, 2017
337 views
bbnlbsnlclinlcbarc application without gate score