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:
138 comments Page 1 of 14.

TP.Swamy said:   3 years ago
Continue will throw the controller to the beginning of the loop while break will terminate the loop.
(1)

Laljijosh said:   4 years ago
Ans 0 is True.

Because x= -1
Negative value stored in 2'nd compliment.
(-1 ) 2nd compliment value is definatly x>10.


And for loop condition is x<=10.
Condition False and out of the loop.

So, the Ans is 0.
(6)

Seghrajeshwar said:   5 years ago
Hello ,please give me the suggestion for this.

#include<stdio.h>
int a,b,z,c;
float x=0.00,y;
float value=200;
void main()
{
x=value/200;
a=x;
y=x-a;
b=23*y;


for(z=0;z<23*a;z+=23)
{
printf("\n Z:%d ",z);
}
if(z<=z*a)
{
c=z;
z=c+b;

In a above code, I want a 23 value print on printf line. Now I am getting the 0 value. How to predict it? please tell me.

Vadivel said:   5 years ago
#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=18; x++)
{
if(x<5)
printf("\nIndiaBIX");
else
break;
printf("\nIndiaBIX");

}
return 0;
}
Output is 12.

Please explain.
(1)

Rohan said:   5 years ago
@All.

According to my knowledge.

#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++)

/* (i) for loop is initialized with x=-1 and condition x<=10............... */
{
if(x < 5)
continue;

/* (i) First time ->
if (-1<5) , condition true -> continue statement transfer the control to for loop...
(ii) Last time ->
if (5<5) , condition false -> the else part will execute....
*/

else
break;

/* (i) -> the break statement make sure the for loop is terminated.........
(ii) -> it will not print IndiaBix because for loop has been terminated.............. */

printf("IndiaBIX");
}
return 0;
}
(2)

Gururaj said:   6 years ago
Actlly almost all we are not using -1 for initilizng -1 in for loop.

Siva said:   7 years ago
If condition false means it should be executed the else statements?

Then why is not printed one time? Can anyone explain to me?

Ashish said:   7 years ago
Once the value of x reaches 5 it executes else part, which is break statement, break statement terminates loop. This means the control will never encounter printf statement. Hence no 'IndiaBix' will be printed.
(1)

Sri Harsha said:   7 years ago
Continue statement in the loop will not allow to print.

Because when the continue statement encountered by the c compiler it simple goes to the beginning of the loop.

The x gets incremented up to 5 and after that loop will be braked.

Ram said:   7 years ago
Thank you @Ankit.


Post your comments here:

Your comments will be displayed after verification.