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

For Loops in PHP Forum

View Course » View Exercise

183 points
3d4f2c5c2534a58a5652f24444e5f9b2?s=140&d=retro
Submitted by
vineethaljapur
almost 3 years ago

why does i get 12 when there is semicolon?

<?php
// Echoes the first five even numbers
for ($i = 2; $i < 11; $i = $i + 2) ;{
echo $i;
}


1 vote

permalink

this ; should be removed

<?php
// Echoes the first five even numbers
for ($i = 2; $i < 11; $i = $i + 2)**;**[<==remove]{
echo $i;
}

589 points
Picture
Submitted by
Ziana Nicole Mitchell
over 2 years ago


0 votes

permalink

Wrong Syntax:


for($i=2; $i<11; $i+=2){
echo $i;
//If you mean to have this show on multiple lines; include a line break:
// echo $i.'<br/>';
}

The issue you have, is that between your last ) and the first { you typed ;.

267 points
Picture
Submitted by
Louis Milotte
almost 3 years ago