C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - General Questions (Q.No. 1)
1.
How many times "IndiaBIX" is get printed?
#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("IndiaBIX");
}
return 0;
}
Discussion:
142 comments Page 1 of 15.
Srinivasa.S said:
2 decades ago
The condition x<5 is true until x=5, so the true block executed. The code after the continue statement(including printf("IndiaBIX");) will not executed and go to increment step(x++). Again the loop is continued.
When x=5, then else block executed, it has break statement, So loop is terminated.
Here the control never go to printf("IndiaBIX"); statement.
When x=5, then else block executed, it has break statement, So loop is terminated.
Here the control never go to printf("IndiaBIX"); statement.
(1)
Amit said:
1 decade ago
The continue statement transfers the control to the next iteration in the loop (increment step).
SANDEEP KUMAR SINGH said:
1 decade ago
The first condition is x<5, that's why loop will continue and keep incrementing value of x until x=5.
When x=5 then condition will go to else part and since break statement is there it will come out of loop.
So, it is not going to print "IndiaBIX".
When x=5 then condition will go to else part and since break statement is there it will come out of loop.
So, it is not going to print "IndiaBIX".
Manya said:
1 decade ago
Thank you Sandeep.
Himani said:
1 decade ago
Thanks all of you. You all have cleared my doubt.
Vignatha said:
1 decade ago
Ya after the continue and break stmts nxt part o code z nt xcuted n goes to iteration, for that der z no output.
Dhivakar said:
1 decade ago
Untill x<5 the 'if' part gets executed,which contains the 'continue' statement and it simply transfers the control to the begining of the loop iteratively for 6 times....
and now x=5 the control passes to the else part which contains the 'break' statement before printf and hence the loop gets terminated before printing "indiabix"
and now x=5 the control passes to the else part which contains the 'break' statement before printf and hence the loop gets terminated before printing "indiabix"
Neha Singla said:
1 decade ago
The value of x is nt declared before the for loop, so it will not enter the loop and program will exit....
Pandu said:
1 decade ago
It prints 0 times because
unit x<5 the 'if' part gets executed,which contains the 'continue' statement and it simply transfers the control to the begining of the loop iteratively for 6 times....
unit x<5 the 'if' part gets executed,which contains the 'continue' statement and it simply transfers the control to the begining of the loop iteratively for 6 times....
Karthi said:
1 decade ago
The continue statement transfers the control to the next iteration in the loop
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers