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

For Loops in PHP Forum

View Course » View Exercise

1189 points
07e521a159252e4035fa5efb86b7d0b1?s=140&d=retro
Submitted by
CatRaper
over 4 years ago

"All On Your Own" done with a for loop instead of foreach

I just thought this was cool. The lesson really should have had you do it both ways.

<html>
  <head>
    <title></title>
  </head>
  <body>
    <p>
      <?php
        for ($i = 50; $i >= 10; $i = $i - 10)
        {
            echo "the $i... ";
        }

        echo "touchdown!";
      ?>
    </p>
  </body>
</html>




Then for a really slow runner all you'd have to do is this:

<html>
  <head>
    <title></title>
  </head>
  <body>
    <p>
      <?php
        for ($i = 50; $i >= 1; $i = $i - 1)
        {
            echo "the $i... ";
        }

        echo "touchdown!";
      ?>
    </p>
  </body>
</html>

1 vote

permalink

Yep, you can accomplish it many different ways but gotta follow the lesson to pass :)

1302 points
6fe2f0b6d4bf3ab714ff3a1bd653cafb?s=140&d=retro
Submitted by
tulagak
over 3 years ago