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 4 of 15.
Varsha said:
1 decade ago
I agree with Sanjeev kumar, thanks.
S.sivaraj said:
1 decade ago
Yes I agree above this answer.
Prasanth Reddy.d said:
1 decade ago
Since x is an integer it has a range from -32768 to +32767.Here x value is -1.x checks the condition x<=10 and enters into for loop and then checks that x<5.since it is true continue; statement executes and since no stmt's are there in if condition, it exits from if loop.
Then x gets incremented and goes as 0,1,2,3,4.It continues as above upto x=4.
when x=5, it goes to else condition and executes the stmt break;
finally coming out of the else condition and x gets incremented to 5,6,7,8,9,10.
Thus by not printing IndiaBIX.
Then x gets incremented and goes as 0,1,2,3,4.It continues as above upto x=4.
when x=5, it goes to else condition and executes the stmt break;
finally coming out of the else condition and x gets incremented to 5,6,7,8,9,10.
Thus by not printing IndiaBIX.
Ramnayan said:
1 decade ago
Here for loop executes 06 times when control enters to loop untill i<5 continue keyword is executeddue to which it skips all the code below the continue regain increment the 'i' when i just reach the 5 else is executed and break keyword through the control just outside the loop in this way not printf statement is executed.
Dileep said:
1 decade ago
Thanks to all of you.
Bhargavi said:
1 decade ago
Since we use break statement it automatically comes out of the else loop, no matter whether it satisfies if condition or not,
Sandip k vaghasiya said:
1 decade ago
Here look at the program x is < 5, the if condition is satisfied and continue is encountered so the loop continue execution without executing the following statements. and when the value of x becomes 5, break is encountered and the control is transferred outside the loop. So 'IndiaBix' will not be printed even once.
Bandita said:
1 decade ago
Thnks Srinivas and sandeep
Basant kumar soni said:
1 decade ago
When the loop is start from -1 to 10 ,firstly check the if condition and follow the continue statement and from -1 to 5 condition is satisfied ,then 6 condition is satisfied and else statement go to break and terminate the loop
so that nothing will be print
so that nothing will be print
Manish NIITian said:
1 decade ago
First you know that how to work Break and Continue statement :.
If you use 'continue' statement then that after particular condition loop will be continue in same loop and another break statement, if you use 'break' statement then terminate of that loop and go to out of loop and program will be exit.
So in this program, println ("IndiaBix") ; is used after break statement so this program is terminated. So no display any output.
If you use 'continue' statement then that after particular condition loop will be continue in same loop and another break statement, if you use 'break' statement then terminate of that loop and go to out of loop and program will be exit.
So in this program, println ("IndiaBix") ; is used after break statement so this program is terminated. So no display any output.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers