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

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

Narmada said:   1 decade ago
Thank you sayali.

Amrita Roy. said:   1 decade ago
I agree with Sandeep.

Yuva said:   1 decade ago
I agree with sanjeev kumar answer.

Soumya said:   1 decade ago
Thnks to sandeep. Its correct.

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.

Vadivelan said:   1 decade ago
Thanks Friends

Shweta said:   1 decade ago
Thanks fellas.

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

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.

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


Post your comments here:

Your comments will be displayed after verification.