A question regarding for loop

M

moijes12

Hi

I have a question regarding the for loop.

Suppose I write the below code :

#include <stdio.h>

int main(){

for( ; ; )
printf("Hello World\n");

return 0;
}

Now I am yet to try the above code but I assume the above code should
not have any output because there is no test expression.So the test
expression should evaluate to 0(False) rather than 1(True).

Please let me know what you think of this.

regards
moijes
 
B

Ben Bacarisse

moijes12 said:
I have a question regarding the for loop.

Suppose I write the below code :

#include <stdio.h>

int main(){

for( ; ; )
printf("Hello World\n");

return 0;
}

Now I am yet to try the above code but I assume the above code should
not have any output because there is no test expression.So the test
expression should evaluate to 0(False) rather than 1(True).

You really need a good book about C. You won't be able to learn a
programming language by guessing what the various constructs do (even if
you the post here). A good text will simply tell you.
Please let me know what you think of this.

As it happens, a missing text expression is a for loop is taken to be 1,
not 0.
 
M

Mark Bluemel

Hi

I have a question regarding the for loop.

Suppose I write the below code :

#include<stdio.h>

int main(){

for( ; ; )
printf("Hello World\n");

return 0;
}

Now I am yet to try the above code but I assume the above code should
not have any output because there is no test expression.So the test
expression should evaluate to 0(False) rather than 1(True).

What does your C reference book say this construct does?
Please let me know what you think of this.

I'm half inclined to think you're a troll.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top