Follow The New Tutorial updates on WhatsApp, Telegram or YouTube.

PHP do-while loop

The PHP do-while loop is guaranteed to run at least once. It executes the code at least one time always because the condition is checked after executing the code.

The do-while loop is very much similar to the while loop except the condition check.

Syntax

do{  
//code to be executed  
}while(condition);  

Flowchart

PHP do-while loop flowchart

Example

<?php    
$n=1;    
do{    
echo "$n";    
$n++;    
}while($n<=5);    
?>   
PHP do while loop Example

A semicolon is used to terminate the do-while loop.