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 2 of 15.
Akhil said:
10 years ago
I. Break statement "STOP's" executing the loop.
II. Continue will execute the next instruction.
1st iteration: x = -1.
Process: if (x<5) [condition true] so "continue" executes and control goes to "else" where we break the loop and iterate again.
So the statement actually never gets printed.
II. Continue will execute the next instruction.
1st iteration: x = -1.
Process: if (x<5) [condition true] so "continue" executes and control goes to "else" where we break the loop and iterate again.
So the statement actually never gets printed.
(1)
Ram said:
9 years ago
Thank you @Ankit.
(1)
Sri Harsha said:
9 years ago
Continue statement in the loop will not allow to print.
Because when the continue statement encountered by the c compiler it simple goes to the beginning of the loop.
The x gets incremented up to 5 and after that loop will be braked.
Because when the continue statement encountered by the c compiler it simple goes to the beginning of the loop.
The x gets incremented up to 5 and after that loop will be braked.
(1)
Ashish said:
9 years ago
Once the value of x reaches 5 it executes else part, which is break statement, break statement terminates loop. This means the control will never encounter printf statement. Hence no 'IndiaBix' will be printed.
(1)
Aashiya said:
2 years ago
Their is 5 times india fix is printed before the break of for loop..
(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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers