# maybe a funny question about 'for'

• 04-23-2004
arian
maybe a funny question about 'for'
hi .
maybe it is funny but I realy cant undrestand why the program go to loop with this instruction
for(i=0;i=5;++i) :confused:

when it is
for(i=o;i<5;++i)
program checks : if i<5 then it does the loop instructions and then ++i
else it doesnt .

when it is
for(i=0;i=!5;++i)
while i isnt 5 the program does the loop instructions and each time ++i

I think when it is "for(i=0;i=5;++i)" PC shoulnt do the loop instruction
(cause i is 0 and i!=5) , but it does .

can u plz explain for me why the program does that and goes to loop ?

TNX :)
• 04-23-2004
tjohnsson
Quote:

I think when it is "for(i=0;i=5;++i)" PC shoulnt do the loop instruction
(cause i is 0 and i!=5) , but it does .
it loops because you
set 5 to i and it loops until 'i' is not true...
i think you have meant to write: for(... ;i == 5; ...) { ... } to test is 'i' 5 or something else...
• 04-23-2004
Salem
> for(i=0;i=5;++i)
This loops forever, it is interpreted as
for(i=0;(i=5)!=0;++i)
Since the test is always in effect 5 != 0, it will loop forever

> for(i=0;i=!5;++i)
You mean
for ( i = 0; i != 5; ++i )
• 04-23-2004
arian
thanks alot for ur help . I undrestand .