What is a loop in PHP

Example of a For loop

This for loop contains 10 lines with the content:
This is the row number: + (consecutive row number => is the result of the incremented variable $ i)
issued among each other.

The For loop in detail

Here a variable $ i with the value 1 is created ($ i = 1;).
The loop starts with the start value $ i = 1.

The condition for executing the loop is now formulated. $ i <= 10;
The loop continues as long as the value of the variable $ i is less than or equal to the value 10.

Finally, the change behavior of the counter variable is determined. With $ i ++ the variable $ i is increased by the value "one" after each loop pass.

In practice, the variable $ i defines the number of loop iterations.

Initially, $ i receives the value 1, and a subsequent flow condition checks whether the variable value is less than or equal to 10. As long as this condition is true, the loop is executed. Finally, the variable is incremented by 1 in the loop head.

In the body of the loop, an echo command is used to output a text that contains the value of the incremented variable at the end.

It is important that the individual statements in the loop head are separated from one another by a semicolon. In the case of multi-line instructions, the instructions must be enclosed in curly brackets in the body. In the case of single-line instructions, however, this is not absolutely necessary.