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

Laljijosh said:   6 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.
(31)

Aniruddha giri said:   1 year ago
Here, printf("IndiaBIX");: this statement is intended to print "IndiaBIX" but it's placed after the break statement. So it didn't print anything.

Correct me, If I'm wrong.
(12)

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

Akshay Kadiyam said:   1 year ago
Since -1<=10 for loop get initialised.

Also, -1 <5 if the condition is true.

The printf("IndiaBIX"); statement gets skipped because of the continue statement that immediately follows it.

Continue statement directly goes to the next iteration skipping the code below it so printf does get executed
(9)

Rohan said:   7 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;
}
(5)

Seghrajeshwar said:   7 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.
(5)

Ankit Kumar said:   9 years ago
When x=-1 to x=4 in this case, continue statement executed by increasing value of x only not go to print statement

When x=5 in this case break statement executed and loop will terminated

So zero times print statement executed.
(3)

Vadivel said:   7 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.
(3)

Srinivasa.S said:   2 decades ago
The condition x<5 is true until x=5, so the true block executed. The code after the continue statement(including printf("IndiaBIX");) will not executed and go to increment step(x++). Again the loop is continued.

When x=5, then else block executed, it has break statement, So loop is terminated.

Here the control never go to printf("IndiaBIX"); statement.
(1)

Roger said:   10 years ago
After 6 loops it will exit.
(1)


Post your comments here:

Your comments will be displayed after verification.