...

>

For Loop

For Loop

This lesson will teach the concept and implementation of for loops and nested for loops in PHP.

What is a for loop?

A for loop can also be used for doing things a certain amount of time. It’s like a while loop but the increment is included with the condition.

Syntax

A for loop is set up like this:

Explanation

  • Initialization - Initialize the variable that will be used as loop control variable.
  • Condition - The loop only runs when the condition is true.
  • Increment - How the variable changes every time the loop runs.

Example

Here’s an example of how the for ...