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

Guna said:   1 decade ago
The program with using continue we get result.

But if using any body of while, do, for break statement (true or false) not get out put.

Yogesh Sharma said:   1 decade ago
The printf Code Line is unreachable in the function

As The control from the if Statement is revert back to For loop increment till x<5 and as it become greater than 5 it stop executing the program.

That is in any circumstances the Printf Code is not executing.

Hence Option C is correct

Anand kumar said:   1 decade ago
Thanks you for all...........

Disha said:   1 decade ago
Thanks to sandeep.

DKBOSS said:   1 decade ago
This will printed one time ; please check your sequence and then discuss.

Vivek said:   1 decade ago
No output will be there for this code.

Prajith&ratnaji said:   1 decade ago
Thank you very much for clearing our doubt.

Purushottam kumar said:   1 decade ago
Here inside the program x is < 5, the "if" condition is true and continue is encountered so the loop continue inside 'for' execution without executing the following statements. and when the value of x becomes 5, 'break' is executed and the 'for' loop will be terminated , So 'IndiaBix' will not be printed even once because 'printf' will never executed.

Shweta said:   1 decade ago
Thanks fellas.

Actually I missed to notice that 'printf' is within 'for loop', and made mistake.

Vadivelan said:   1 decade ago
Thanks Friends


Post your comments here:

Your comments will be displayed after verification.