FOR LOOP

FOR loop

Sometimes you need to perform an action specified number of times. It is used for the FOR loop. The overall record looks like this:

Example

<? php

for (initialization of variables to check the condition, modify variables) {

block expressions

}

?>

The loop will execute until the condition is true, and modify variables that control loop. Without this loop will execute on forever (of course the value of these variables can be modified inside the loop, but this is not recommended). An example of a loop that prints the numbers from 1 to 10:
Example

<? php

for ($a = 1; $a <= 10; $a ++)
echo $a. „<br>”;

?>

 

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Info | Close