This forum is now read-only. Please use our new forums at

165 points
Submitted by
about 5 years ago

Why would the first $i be echoed out?

Am I reading this wrongly?
Isn't the $i being updated before the end of the statement in the loop?

1st step: $i = 0;
2nd step: check wether $i is still smaller than 10; if it is go to step 3
3rd step: update the value of the variable $i by incrementing it with 1.

The result should then be: 123456789 instead of 0123456789, no?

Or is the initial setting of the variable $i a statement for the loop to know where to start?

"where to start the loop;"

1 vote


If you set $i =0 at the begining of the for-loop, the echo will print out the 0.
Maybe I can explain it to you by a while-loop:

$i =0;
    echo $i;

This is how a for-loop works, first it checks if the statement is true, if so it continues the code and after this, it increments the loop-variable.
I hope you got it
and sorry for my grammar ;>

563 points
Submitted by
about 5 years ago

1 Comment

574eb20c6eb9714a3e000359_387000418 Kannuki Wakaba almost 5 years ago

That was very helpful. Thank you.