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

K. Parthi said:   1 decade ago
The statement will be executed until x IS 5 THEN it terminates the loop by break, prints return 0.

Vishnu o.m said:   1 decade ago
Indiabix is not printed because the continue instruction will take the control back to the for loop until i<5, till then printf don't get executed. When if statement fails, else statement break is executed which will take the control out of the loop. Hence printf is not executed.

Ayodhya Prasad said:   1 decade ago
Since loop will execute until condition is true. After break it will not execute. Hence it will not print the IndiaBix.

Harsha said:   1 decade ago
When break is encountered in loop then the control directly jumps to the first statement after the loop.

Srinu said:   1 decade ago
Break and continue statements does not allow to execute printf statement.

Amol said:   1 decade ago
The continue statement takes the control out of the loop for the next iteration and the break terminates the loop.

Mayank said:   1 decade ago
Because when ever the break statement given in loop.

The loop terminates and control get out from the loop.

K@vy@ said:   1 decade ago
Here when the loop start if x<5 it will continue but it won't print anything otherwise if x>5 it will take else statement and it will break. If it breaks there won't be any printing. So there is no printing of indiabix.

Keshav saini said:   1 decade ago
Here printf ("IndiaBIX") ; is unreachable code. Because break keyword is stop the working of the block.

Himanshu said:   1 decade ago
Hi agi. No matter you take value of i=1 or something else only the value inside the loop will be executed. So take i=1 or 100 or 200 loop will work for i=-1.


Post your comments here:

Your comments will be displayed after verification.