🚀 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!

While, Nested While, Do While, and Nested Do While Loop in PHP.

While Loop

The While loop keeps repeating an action until an association condition returns False. It means that when a while loop started, it checks the condition, if it’s true then it executes the block of statements and then rechecks the condition and executes until the condition gets False.

Syntax

initialisation;
while(condition)
{
block of statement;
increment/decrement;
}

Sample Program

<?php
$num = 1;
while ($num<=5)
{
echo "sushant count: $num<br>" ;
$num++;
}
echo "Loop end's here";
?>

Output

Sample program-2

<?php
$num = 1;
while (true)
{
echo "sushant count: $num<br>" ;
$num++;
if($num==10)
break;
}
echo "<br>loop ends here";
?>

Output

Nested While Loop

When we insert a while loop under a while loop then, it is called Nested While Loop.

Syntax

Sample Program

<?php
$num = 1;
while ($num<=2)
{
echo "sushant count: $num<br>" ;
$num++;
$val=1; /* inner while loop starts
while($val<=2) ..................
{ ..................
echo "value is : $val <br>"; ..................
$val++; ..................
} inner while loop ends*/
}
?>

Output

Do While Loop

The Do-While Loop is similar to while Loop, but the condition is checked after the loop body is executed. This ensures that the loop body is run at least once.

Syntax

initialisation
do
{
block of statements;
increment/decrement;
}while(condition);

Sample Program

<?php
$num = 1;
do
{
echo "sushant count: $num<br>" ;
$num++;
}while($num<=4)
?>

Output

Nested Do While Loop

When we insert a Do-while loop under a Do-while loop then, it is called Nested-Do-While loop.

Syntax

initialisation
do
{
block of statements;
increment/decrement;
do
{
block of statements;
increment/decrement;
}while(condition);
}while(condition);

Sample Program

<?php
$num = 1;
do
{
echo "Outer do-while count: $num<br>";
$num++;
$val = 1;
do
{
echo "inner-do-while count: $val<br>";
$val++;
}while ($val<=3);
}while ($num<=2);
?>

Output

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.