Pattern: Jumbled loop incrementer
Issue: -
To avoid confusion, incrementers in nested loops should use different variable names.
Example of incorrect code:
// $i is used in both loops
for ($i = 0; $i < 10; $i++) {
for ($j = 0; $j < 10; $i++) {
do_something($i, $j);
}
}
Example of correct code:
for ($i = 0; $i < 10; $i++) {
for ($j = 0; $j < 10; $j++) {
do_something($i, $j);
}
}