# maybe a funny question about 'for'

This is a discussion on maybe a funny question about 'for' within the C++ Programming forums, part of the General Programming Boards category; hi . maybe it is funny but I realy cant undrestand why the program go to loop with this instruction ...

1. ## 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)

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

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

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

4. thanks alot for ur help . I undrestand .