For Loop
Home Courses Community Support
For Loop

For loop in PHP is the most complicated loop. We use this loop when we know how many time the code should run.

Syntax for for loop is as below-

for (expression1, expression2, expression3) {



First expression executed at the beginning of the loop. Post execution of first expression, the second expression executed. If the second expression returns true then statement executed. And if the second statement returns false, the loop end.

Third expression executed at the end of the loop. Each of the expressions can be empty or contain multiple expressions separated by commas.

See below example -

for ($i=1; $i<=5; $i++) {
	echo $i;




In the above code value of i was set to 1 and printed. Each time it was printed, increased by 1 and checked whether it is <= 5.



← Preview

Do While Loop

Next →

ForEach Loop


Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.


  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App