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

Agi said:   1 decade ago
int i=1
for(i=-1;i<=10;1++)
Then how it calculate -1 in for loop ?
Then how many it print?
Please explain this.

Rohit said:   1 decade ago
Can someone please tell me why the output is 27 for the following code?

#include<stdio.h>
int main()
{
int b=5;
int c= ((b++) + (++b) + (++b) + (++b));
printf("%d",c);
return 0;
}

Adil saifi said:   1 decade ago
True block evaluated continuously tat is (x<5)0,1,2,3,4 until 4<5 when 5<5 condition checked the condition bcm false then the control pass to else block which will break and exit. but if u want to print the given statement just write it upon the break statement it will print 1 time indiaBIX on ur output screen.

Jayaprasad said:   1 decade ago
Good Ritesh...
In the above program the "IndiaBix" will be printed 12 times because...

At x= -1,0,1,2,3,4 i.e 6 times the condition x<5 is satisfied so the statement in the if block and the one after the block(in the loop level) will be printed... As both the statements are "indiaBix" it will be printed 12 times(6x2).......

After x=4 i.e at x=5,6,7... the condition x<5 is not satisfied so the control is transferred to else block which contains break; statement. here break; terminates the loop execution so nothing is printed after x=5.....

So only 12 times it is printed...

Anita said:   1 decade ago
The "Continue" Statement Takes the control to the beginning of the loop,So When ever value of if(x<5) continue appreas,control goes to begining of loop and value of X is incremented.

"Break" Satatement takes the control out of the loop.So when it is occured,control is taken out of the Loop.

Thus "IndiaBix" Will never get printed.

Divyasree said:   1 decade ago
control never goes to printf("IndiaBix"); statement.. So there exists compilation error.. Hence the solution is 0 times

Hitesh Soni said:   1 decade ago
Continue takes the control to the beginning of the loop. Therefore as far as x<5, nothing happens.

As soon as value of x is 5,break statement takes the control outside the loop body.

Nithin said:   1 decade ago
Will break and exit statements work similarly ?

Sriram kumar 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.

Raviteja Kokkula said:   1 decade ago
In the above program the "continue" statement is like

if (x < 5) continue;

this continue statement will take the compiler to continue without further steps and it will go for the "for loop" and it increment the i value until the condition like if (x = 5) and then the compiler execute the ELSE statement i.e. "break;" here the compiler will not reach the "print statement", so it will not execute the printf ("IndiaBIX") ;.


Post your comments here:

Your comments will be displayed after verification.