PHP 5 for Loops

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 of leap years in the editor.

Example -

A loop is a useful bit of code that repeats a series of instructions for you. For instance, instead of typing echo many times like we did above, we can simply use the code in the editor to the right!

PHP for loops execute a block of code a specified number of times.The for loop is used when you know in advance how many times the script should run.



  • Init counter: Initialize the loop counter value
  • Increment counter: Increases the loop counter value
  • Test counter: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends.
  • Example -