[Solved] incrementing values using loops [closed]


If you take close look at for loop, it supports syntax like this:

for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);

So you basically can do this:

for( $i = 1, $j = 0.5; $i < 200; $i++, $j += 0.5){
    // Do stuff
}

Although I think this may confuse some people and it’ll be more readable to write it this way:

$j = 0;
for( $i = 0; $i < 200; $i++){
    // do stuff

    $j += 0;
}

Or you could also calculate $j in each step:

$j = $i/2; // Before do stuff block

But I think this will have worse performance then just incrementing it;

2

solved incrementing values using loops [closed]