Writing Your First ‘For’ Loop PHP (Codeacademy)

Writing Your First ‘For’ Loop PHP (Codeacademy)

Here is a correct example:

1
2
3
4
5
6
7
     <?php
      // Write your for loop below!
      for ($i = 10; $i < 101; $i = $i + 10)
        {
            echo $i . " ";   
        }
      ?>

Notice that the “for” loop has a simple syntax with having round brackets for the condition and having curly brackets to start and end the condition. Also, use semicolon instead of coma as syntax, inside the “for” statement.

“For” loops are used when you already know for how many times you have to loop while “do” or “while” loops, don’t know the exact number.

Add a comment: