You are on page 1of 19

Soren technical institute

IT department

PHP Loop

Student by : Zanyar Hasan , Razaw Sabir ,


Zebar Frsat , Maqsud Ado
Supervisor by: Omed Hader
●Table of contents
● What is PHP Loop
● Types of PHP loop
● PHP while loop
● PHP do…while loop
● PHP for loop
● PHP foreach loop
● Reference
WHAT IS PHP LOOP
PHP loop is the process of executing the same block of code again and
again until the specified condition is true. Loops are the best part of the
PHP programming to perform a task many times you want to execute.

Suppose you want to echo a statement 20 times and you don’t know
about PHP loops. You start typing the same statement 20 times. This
takes time and more human effort. Now, to save this extra effort, you can
use Loops with the condition that perform the repetitive task for 20 times.
Types of PHP loop
There are four types of loops in PHP. You can
use these tasks to perform repetitive tasks:-
● PHP while:- While condition executes a block of code
again and again until the specified condition is true.
● PHP do…while:- It first executes the block of code and
then after executes this block of code again and again
until the specified condition is true.
● PHP for:- For condition executes a block of code at a
specified numb of times.
● PHP foreach:- The loop can be used to iterate through
each element of an array.
PHP WHILE LOOP
PHP while loop executes a block of code again and
again until the given condition is true. The loop first test
the condition if it is true and if the condition is true, it
executes the code and returns back to check the
condition if it is true.
The process repeats itself and executes the code. If the
condition is false, the loop stops executing the code
and stop the loop also.
EXAMPLE OF PHP WHILE LOOP
THE EXAMPLE PRINTS THE NUMBER FROM 0 TO 9.
OUTPUT
PHP DO…WHILE LOOP
PHP do…while loop first executes a block of code and
then after checks the given condition is true. The code
will execute for the second time only if the given
condition is true and the loop repeats itself again and
again until the condition is true.
Example of PHP DO…..While loop
the example prints the number from 0 to 9.

OUTPUT
OUTPUT
PHP FOR LOOP

PHP for loop repeats the execution of a block of


code for a certain number of times you specified.
You can use this loop when you have an idea
about how many times you to run the script again
and again.
Example of PHP for loop
the example prints the number from 0 to 9.
OUTPUT
PHP FOREACH LOOP

PHP foreach loop can be used to iterate through each element of an


array. Foreach loop works only with arrays. You can print each element
of an array using PHP echo statement. The major benefit of computer
networks for large companies is that lots of resources can be shared to
all the staff through it. It assures that the resources needed for the
completing operation can be shared completely.
Example of PHP foreach loop
the example prints the number from 0 to 9.
OUTPUT
OUTPUT
Reference
● https://www.geeksforgeeks.org/php-loo
ps
/
● https://tutorialdeep.com/php/php-loop/

You might also like