0

I have this for-loop in PHP which isn't working:

for ($i = 0; $i <= 100; $i = $i + 10) {
    echo $i;
}

and this one that does work:

  for ($i = 0; $i <= 100; $i = $i + 10) {
echo $i;
}

I'm sure that I'm missing something, but they appear to be exactly identical to each other. What's the difference? The first one was copied and pasted, the second one typed by myself. What's the difference? Why isn't the second one working? The error is this:

This is the error message:

Parse error: syntax error, unexpected ')', expecting ';' on line 12

Line 12 is the first line of the code in the sample (it's from a larger script).

Thamilhan
  • 13,040
  • 5
  • 37
  • 59
Leshy
  • 97
  • 1
  • 13

1 Answers1

1

The loops are exactly the same and they both work, you must have any other error on the script, although, you can use :

$i+=10;

instead of:

$i = $i + 10
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268