The best PHP While loop Tutorial In 2024, In this tutorial you can learn PHP loop,while loop,do ... while statement,
Loop executes a block of code a specified number of times, or when a specified condition is true loop code block is executed.
When you write code, you often need to make the same block of code to run over and over again. We can use looping statements in your code to accomplish this task.
In PHP, we provide the following loop:
while loop repeats a block of code until a specified condition is not satisfied.
The following examples set the first value of the variablei is1 ($ i = 1;) .
Then, as long asiis less than or equal to 5, while loop will continue to run. Each time you runloop,it is incremented 1:
Output:
do /en. while statement will execute the code at least once, and then checks the condition, as long as the condition is true, it will repeat the cycle.
The following examples set the first value of the variablei is1 ($ i = 1;) .
Then, start do /en. while loop. The value of the loop variableiis incremented by one, and then output. Check the condition(iis less than or equal to 5), as long asiis less than or equal to 5, the loop will continue to run:
Output:
foreach loop for circulation and will be explained in the next chapter.