What Is Loop
Loops in PHP are used to execute the same block of code a specified number of times. This is called the body of the loop. Every loop depends on the condition. It keeps executing the block of code unless the condition is met true or stands false (depends on the loop’s type that we will discuss in a moment).

There is a terminating point for each loop that ends the loop when the condition is satisfied. Like in our earlier discussed example if we want to display a hundred lines of ten equal signs each then we have the following attributes that will make up our loop in theory;
Condition:
- hundred lines: keep printing unless a hundred lines are printed.
Body of the loop:
- in which we will put the printing stuff that is echo statements to print equal signs plus some additional contents that will help our loop to execute for the desired number of timing (will discuss in a moment)
Terminating Point:
- when a hundred lines are printed the loop must terminate
Loop Run:
- Every time the block of code (body of the loop) executes the loop completes its one RUN.
- Isn’t it easy? Yeah, it is and it will be more easy for you once we discuss the actual loops. So let’s do it!
Remember, I am using these terms from my own dictionary because I will use them to explain things otherwise these terms or not standard and attached with loops definitions you can use whatever theory you want to explain these terms in your own words.
Types Of Loops:
PHP supports the following four loop types.
for loop :
- loops through a block of code a specified number of times.
while loop :
- loops through a block of code if and as long as a specified condition is true.
do...while loop:
- loops through a block of code once, and then repeats the loop as long as a special condition is true.
foreach loop :
- loops through a block of code for each element in an array.
We will discuss about continue and break keywords used to control the loop's execution.
