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 12 of 15.
Vaibhav said:
1 decade ago
for (x<5) five times the control will go t starting of loop due to continue. And after for the else condition the break occurs so control will go out of loop so there wont be any printing
Rajan said:
1 decade ago
Continue is for break current iteration. So that it gets increments and avoids the further steps and break is for break current loop. Therefore the loop is terminated.
Srikanth said:
1 decade ago
Good answer srinivasa.
Rohit 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.so that the ans c is rite
Ajeet said:
1 decade ago
Thanks to everyone.
Sarasa said:
1 decade ago
The value of X is -1 so again and again to execute the loop to increase the value in X is minus value so infinte times to execute the loop.
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.
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
Bandita said:
1 decade ago
Thnks Srinivas and sandeep
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers