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 3 of 15.

Dileep said:   1 decade ago
Thanks to all of you.

Bhargavi said:   1 decade ago
Since we use break statement it automatically comes out of the else loop, no matter whether it satisfies if condition or not,

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.

Bandita said:   1 decade ago
Thnks Srinivas and sandeep

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

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.

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.


Post your comments here:

Your comments will be displayed after verification.