For Loops in PHP 1/7

What's a Loop?
Programming can be tough work, and sometimes it's made tougher by having to do the same thing over and over. Let's say we want to echo a list ofleap years in the editor. You might think we'd have to type:
<?php
    echo 2004;
    echo 2008;
    echo 2012;
    // And so on
?>
But there's a better way!
loop is a useful bit of code that repeats a series of instructions for you. For instance, instead of typing echomany times like we did above, we can simply use the code in the editor to the right!
Instructions
Check out the for loop in the editor. See how it echos the value for $leap, adds four to it, then repeats? Click Save & Submit Code to learn how it all works!
What's a Loop? 1/7
<html>
  <head>
    <title>Leap Years</title>
  </head>
  <body>
    <?php
      for ($leap = 2004; $leap < 2050; $leap = $leap + 4) {
        echo "<p>$leap</p>";
      }
    ?>
  </body>
</html>

Comments

Popular posts from this blog

MEGA 暫存檔案刪除

IOS GCD多執行緒

利用CMD指令強制刪除