No way in 3. Writing Your First 'For' Loop


#1

I try to finish ex with code
for ($i=10; $i < 101; $i=$i+10 ){
echo $i;
}
but still there are errors


#2

Hello @xtfkpi,
check the exercise - is the way you do it really the right way? :wink:

Write a for loop that counts up by 10, all the way to 100 (e.g. 10, 20, 30...). Inside the for loop, echo the current value of $i, just like in the examples above.

First, there is a cleaner way to increment a variable by x (in this case, a better solution than $i = $i + 10 )
Second, it should count all the way to 100, so there's also a cleaner way to set this condition than $i < 101.

Here the "correct" code:

<?php
  // Write your for loop below!
  for($i = 10; $i <= 100; $i += 10) {
      echo $i;
  }
?>

Think about it. Hope this will help you understanding further exercises :slight_smile:


#3

The instructional sidebar is instructing students to use the following syntax:

for ($i = 0; $i < 11; $i = $i + 5) {
echo $i;
}

therefore the answer to the question if one follows these instructions should indeed be what OP posted.
Your syntax for the incremental command is different.
This lesson needs to be corrected.


#4

Try this code:



Solo For Loop!



<?php
// Write your for loop below!
for($i = 10; $i < 101; $i += 10) {
echo $i;
}
?>