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.
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.
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
Geethapriya V said:
1 decade ago
if(x<5) this condition is true then continue keyword go to next iteration of for loop so loop is execute till (-1 to 4)6th iteration . In 7th iteration x=5 so if the condition(x<5) is false then the break keyword is executed (i.e) break keyword is used to jump out of the for loop . The result is 0 times.
Mahesh said:
1 decade ago
Thank you Srinivasa. S.
P.vijayan said:
1 decade ago
continue: go back the control to starting of the loop
break: terminate the execution of the loop
if(i<5) that the values are (-1,1,2,3,4) then control back to loop
else tat is i=5 then terminate the execution
So nothing to be printed.
break: terminate the execution of the loop
if(i<5) that the values are (-1,1,2,3,4) then control back to loop
else tat is i=5 then terminate the execution
So nothing to be printed.
Kvamshavardhanreddy said:
1 decade ago
Giving that if x<5 after that we used continue , it means it performs operation from next line it self after that there is a break statement when compiler performs break it it is out of loop so INDIABIX is not printed.
Sayali said:
1 decade ago
continue will transfer control back to loop statement for i = -1 to 4 since it satisfies condition if (i<5), for i=5 it will satisfy condition in the else part i.e.(!(i<5)) control will go to break statement and break statement will stop executing loop and will come out of loop and will not print indiabix
Narmada said:
1 decade ago
Thank you sayali.
Yuva said:
1 decade ago
I agree with sanjeev kumar answer.
Amrita Roy. said:
1 decade ago
I agree with Sandeep.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers