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

Output

Sample program-2

Output

Nested While Loop

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

Syntax

Sample Program

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

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

Output

Total Page Visits: 97 - Today Page Visits: 1