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.

Dhivakar said:   1 decade ago
Untill x<5 the 'if' part gets executed,which contains the 'continue' statement and it simply transfers the control to the begining of the loop iteratively for 6 times....


and now x=5 the control passes to the else part which contains the 'break' statement before printf and hence the loop gets terminated before printing "indiabix"

Neha Singla said:   1 decade ago
The value of x is nt declared before the for loop, so it will not enter the loop and program will exit....

Pandu said:   1 decade ago
It prints 0 times because
unit x<5 the 'if' part gets executed,which contains the 'continue' statement and it simply transfers the control to the begining of the loop iteratively for 6 times....

Karthi said:   1 decade ago
The continue statement transfers the control to the next iteration in the loop

Vignesh said:   1 decade ago
Thanks Srinivasa.

Sweety said:   1 decade ago
The statement cannot executed the statement of x so the process of IndianBIX executed the statement executed 0times.

Sanjeev kumar said:   1 decade ago
Basically x is initialized with -1. As x<5 (since x is -1) it will came with continue statement.

Continue means "stop the current iteration and go to the next iteration". So x becomes 0 now. This will be happened until x becomes 5. Now if x=5, it will enter the else part where it encounters break statement, as a result it will come out of for loop. As a result it will not go to printf statement. So IndiaBIX will be printed 0 times.

Owais dar said:   1 decade ago
The value of x starts from -1 and is incremented everytime till x<5. becux the continue statement sends the control back to increment process. And once the value of x reachs 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.

Ashu said:   1 decade ago
Till 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.

Ajeshbabu said:   1 decade ago
If x is <5 ,if condition will executed, other 6 then loop process is terminated, then return 0 will occur,then final result get 0 times loop occur


Post your comments here:

Your comments will be displayed after verification.