Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!
We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!
Learn from Guru Rajesh Kumar and double your salary in just one year.

In for-loop initialization, condition and increment happen on the same line. The loop keeps on repeating as long as the condition is true.
When the for loop is executed, the variable of the loop is initialized first and then the condition is checked. If the condition is true, then the program control goes to the statement block of the for loop and executes the statements there. When the For Loop statement executes all the statements in the block, it executes the step size part of the loop before exiting the block.
Then does the condition check back. If the condition is true then goes back to the statement block.
This sequence continues as long as the condition of the for loop remains true. Initialization of the loop happens only once.
Syntax:-

for( initialization; condition; increment ){
//statements;
}
Example:-
<?php
echo "This is for loop in action <br>";
for ($index=1; $index < 5; $index++) {
// for(initialization;condition; updation)
echo "This number is $index <br>";
}
echo "For loop has ended";
?>
Output:-

Leave a Reply