Coding Villa

How we can use do-while loop in php.

Author : nida khawar

Share with Friends
Views : 406
Ratings : 0
Bookmarks : 0
Farourities : 0

Description


In this simple article you will learn that how we can use do-while loop in php.


Advertisements


 

 

Do-while Loop:

 

Do-while loop is a control flow statement it is also called do-loop. It must run the code once and then checks the condition and repeat the loop if the condition is true otherwise terminate the loop.

 

Do-while Loop in PHP:

 

When we want to run our code at least once whatever the condition is we use do-while loop because it must execute the code one time and then checks the condition and response according to the condition. In the given code we initialize variable i with 1 and then in do block increment i and print it. This do block must execute at least once then it has to check the given condition that is if variable i is less then and equal to 5.

 

Syntax:

 

do

 {

code to be executed;

}

while (condition);

 

Code:

 

<?php

$i=1;

do

  {

  $i++;

  echo "The number is " . $i . "<br />";

  }

while ($i<=5);

?>

 

Above is a simple code to use do-while loop in php.

 

This simple article tells that how we can use do-while loop in php.

 



Article Tags
Share with Friends

Comments




Leave a Reply

Name (required)  
Mail (will not be published) (required)   
 
Enter This Code
Captcha
 

Advertisements

Article Categories

.NET


Databases


Mobile Development


Operating Systems


Web Development


Coding Villa on Facebook