It seems like the following from the PHP manual regarding for loops is incorrect.
They behave like their C counterparts.
This is my understanding of for loops.
In C
for (i = foo; i < 10; i++) { /* body */ }
is equivalent to
if ( i = foo )
{ while (i < 10)
{ /* body */
i++;
}
}
In PHP the comparable loop
for ($i = $foo; $i < 10; $i++) { /* body */ }
becomes
$i = $foo;
while ($i < 10)
{ /* body */
$i++;
}
The difference is that in PHP $i = $foo is not a condition but rather a convenient place for a statement. Suppose we change the single = to ==. The distinction becomes significant. Is this correct? If so, then PHP and C loops behave differently and the manual is incorrect, right?
They are exactly the same, but your understanding of C’s
forloops is wrong. They are the same as in PHP.is almost like
Though the
forandwhileexamples in C are not exactly the same because of scopes and things.