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;
}
Infinite times
11 times
0 times
10 times
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
142 comments Page 5 of 15.

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.

Ajeet said:   1 decade ago
Thanks to everyone.

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

Srikanth said:   1 decade ago
Good answer srinivasa.

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.

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.


Post your comments here:

Your comments will be displayed after verification.