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 11 of 15.
Raju Naidu said:
1 decade ago
Hai,
The keyword 'continue' is used to skip the some statements and continuing the current process. In our programm till the x=5 it continuing the process once it's reached to 5 if condition getting false so else block will be execute but in else block we had break statement, so it breaks the loop and it will never go to print the indiabix so answer is 0 times.
The keyword 'continue' is used to skip the some statements and continuing the current process. In our programm till the x=5 it continuing the process once it's reached to 5 if condition getting false so else block will be execute but in else block we had break statement, so it breaks the loop and it will never go to print the indiabix so answer is 0 times.
Soumya said:
1 decade ago
Thnks to sandeep. Its correct.
Amrita Roy. said:
1 decade ago
I agree with Sandeep.
Yuva said:
1 decade ago
I agree with sanjeev kumar answer.
Narmada said:
1 decade ago
Thank you sayali.
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
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.
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.
Mahesh said:
1 decade ago
Thank you Srinivasa. S.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers