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.

Vaibhav said:   1 decade ago
Please anyone can explain me this program:

#include<stdio.h>
void main()
{
int s=0;
while(s++<10)
{
if(s>3&&s<10)
continue;
printf("\n%d\t",s);
}

}

Kamlesh said:   1 decade ago
I am not getting any thing.

Abhishek Kumar said:   1 decade ago
The if block will execute upto x=4, when it is x=5, then the if statement become false and it will go to else block, where break statement is given, the break will terminate the program and takes the control out of the program.

Therefore, there will be no output for this program. Option (C) is correct.

Jayapraksah said:   1 decade ago
When the condition is true it will skip the further program by continue. If the condition getting false it will get off the block by executing break statement.

Madhu Chandra said:   1 decade ago
The continue statement under if condition will keep on running the executing for loop by increment 1 and then after 6 iterations the x value becomes 5 by increment 1 and in 7th iteration it will fail, then go break out from loop.

Aliimran224 said:   1 decade ago
Here,

i = i+2*i+1 [Because i++ = i+1].

Now i = 1+2*1+1.

i = 4(Ans).

Premalatha said:   1 decade ago
Guys please anyone can explain me!!!

void main()
{
int i;
i=1;
i=i+2*i++;
printf("%d",i);
}

Output = 4.

Nitika said:   1 decade ago
Till the time x is less than 5 it will satisfy the if condition and will move to continue. And we know that when continue is encountered the loop moves to its starting i.e. here it will go back to for loop.

And when if condition will fail i.e when x>5 the else part will be executed according to which break statement will be encountered and when break is encountered the loop moves to the first statement after that loop.

Therefore here it will go out off or loop. And hence printf will never get executed.

Chirala anil kumar said:   1 decade ago
In this program increment the x value up to x = 5 after that if condition false come out of the loop. Nothing printed.

Bhavin Patel said:   1 decade ago
If condition of the for loop becomes false then loop will be terminated. So, INDIABIX will print 0 times.


Post your comments here:

Your comments will be displayed after verification.