PHP For Loop with Example

PHP For Loop with Examples


The for loop are the most complex loops in PHP.The “for loop” is used when the developer has a clear idea about the number he wants to execute a block of code. The number of required iteration has to be known before writing the loop. This is also known as entry-controlled loops. They behave like their C counterparts. It has three main parts or parameters to code: the initialization part, the condition, and the increment or decrement part.

Basic Syntax of For Loop:

    for (initialization; condition; increment)
   {
     code to be executed;
  }
 
Parameters of for loop :
Initialization :is used to set a counter.
Condition : if condition is true loop will continue, if the condition is false loop ends.
Increment : used to increment the counter
.
 
For Loop Flow Control chart:
 
Example:
Output: