[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

A question regarding for loop

moijes12

3/25/2011 3:19:00 AM

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
3 Answers

Ben Bacarisse

3/25/2011 3:23:00 AM

0

moijes12 <moijes12@gmail.com> writes:

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

--
Ben.

Mark Bluemel

3/25/2011 8:46:00 AM

0

On 03/25/2011 03:19 AM, moijes12 wrote:
> 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.

moijes12

3/26/2011 8:01:00 AM

0

On Mar 25, 1:46 pm, Mark Bluemel <mark_blue...@pobox.com> wrote:
> On 03/25/2011 03:19 AM, moijes12 wrote:
>
>
>
> > 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.

@Ben : Thanks.