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 14 of 15.
Sweety said:
1 decade ago
The statement cannot executed the statement of x so the process of IndianBIX executed the statement executed 0times.
Vignesh said:
1 decade ago
Thanks Srinivasa.
Karthi said:
1 decade ago
The continue statement transfers the control to the next iteration in the loop
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....
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....
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"
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.
Himani said:
1 decade ago
Thanks all of you. You all have cleared my doubt.
Manya said:
1 decade ago
Thank you Sandeep.
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".
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers