While & Do While Loop in PHP – website development

In this video

Today we are going to learn about While & Do While Loop PHP. In our last lecture we learned about IF ELSE in PHP. If you haven’t watched it yet then here is the link of tutorial http://tutorialhive.net/2018/09/08/7-if-else-in-php-php-website-development/ .Today’s tutorial is about While & Do While Loop PHP.

While & Do While Loop PHP

In this tutorial we will learn about While & Do While Loop PHP. First step is to run wamp server. Run wamp and after that go into drive where you installed wamp server. Open folder Wamp after that open folder www. Now create a new folder in ‘www‘ you can give any name to your folder, I am naming it tutorialhive. In folder create a file with name index.php. In your editor open your php file.

While SYNTAX

The while loop statement check condition at the beginning of each iteration. If condition is true, the code inside the curly braces is executed. If the condition is false, the loop terminate.

While (condition is true)

{
    Code to be executed;
}

<?php 
$no = 1;

while($no <= 5) {
echo “The number is: $no <br>”;
$no++;
}
?>

Output: The number is: 1
The number is: 2
The number is: 3
The number is: 4
The number is: 5

Do while SYNTAX

Condition in the PHP do-while statement is checked at the end of each iteration. It means the loop will execute at least once even the condition is evaluated to false.

 

do

{
Code to be executed;
} while (condition is true);

<?php 
$no = 1;

do {
echo “The number is: $no <br>”;
$no++;
} while ($no <= 5);
?>

Output: The number is: 1
The number is: 2
The number is: 3
The number is: 4
The number is: 5

While vs. do-while

The code inside the do-while loop body executes at least one whereas the code block inside the while loop body will not execute at all if condition is false.

The condition in the do-while loop statement is evaluated at the end of each iteration whereas the expression in the while loop statement is evaluated at the beginning of each iteration.

While & Do While Loop in PHP tutorial end here. In next tutorial we will learn about for and for each loop in php. If you have any queries you can ask us on our Facebook page link is given below, Thank you for watching us.

ABOUT US

Tutorial Hive’s mission is to provide quality education to all our community. Tutorial Hive’s mission is to provide free education to all those who cannot afford BIG FEE of institutes. We aim specifically to empower youth to understand programming related knowledge which further helps the society to reduce complex problems through applications. Why Tutorial Hive? We not only provide the theoretical knowledge but also provide the actual implementation with working sample applications. Tutorial Hive cannot achieve its mission without the help of our community. So, please if you think you can help in any manner feel free to contact us. Or if you see any mistake in our content which can be modified/corrected then please leave us a message

We are always open for suggestions.

Facebook: www.facebook.com/hbss2015

Subscribe on YouTube: https://www.youtube.com/channel/UCOUy6kTpedj7s6HOqM0c08w

Follow us on Social Media

You might be interested in

LEAVE YOUR COMMENT

Your email address will not be published. Required fields are marked *