πŸš€ DevOps & SRE Certification Program πŸ“… Starting: 1st of Every Month 🀝 +91 8409492687 πŸ” Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How many types of loops are there in PHP?

While Loop:-
While loop keeps repeating an action until a condition returns false.

<?php
//while loop
$value = 1;
while($value <= 5) //before check if conditon is true then executed if wrong then exit
{
echo "this is while loop : $value <br>";
++$value;
}
?>

Nested While loop:-
Nested while loops work as while loop but in this case, you use one or more while loop condition in one while loop.
ex:-

<?php
#nested while loop
$a = 3;
while ($a <= 4) //before check if conditon is true then executed internal parts with check internal while loop conditions
//if wrong then exit
{
echo "this is example $a <br>";
++$a;
$b = 4;
while ($b <= 5)
{
echo "val $b <br>";
++$b;
}
}
?>

Do While loop:-
Do While loop work as while loop but in this case Before executed then check condition is true then execute next if condition is false then exit.
ex:-

<?php
$a = 5;
do //before executed after condition check
{
echo "this is do while loop $a <br>";
$a++;
} while ($a <= 6);
//second example
$b = 3;
do
{
echo "this is do... while loop $a <br>";
++$b;
} while ($b <= 5);
?>

Nested Do While loop:-
Nested Do While loop work as Do While loop but in this case you can add or use one or more do while loop in one parent do while loop.
ex:-

<?php
$a = 4; //before executed after condition check but one or more
do
{
echo "this is first $a <br>";
$a++;
$b = 5;
do
{
echo "this is second $b <br>"; //first check
++$b;
} while ($b <= 7);
} while ($a<= 6); //second check
?>

For loop :-
For loop is frequently used where you will be a fixed number of times.
ex:-

<?php
for ($a = 2; $a< 5; ++$a) // before check if conditon is true then print and check next if condition is false then exit
{
echo "this is for loop <br>";
}
//second example
for ($b = 3; $b< 6; ++$b)
{
echo "for <br>";
for ($c = 4; $c <7; ++$c)
{
echo "nested for <br>";
}
}
?>

Nested for loop :-
Nested for loop work like as for loop but one or more for loop in one parent for loop.
ex:-

<?php
//Nested for loop
for ($b = 3; $b< 6; ++$b) // before check if conditon is true then print and check next if condition is false then exit
{
echo "for <br>";
for ($c = 4; $c <7; ++$c)
{
echo "nested for <br>";
}
}
?>

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.