- HubPages»
- Technology»
- Computers & Software»
- Computer Science & Programming»
- Programming Languages
PHP Code Looping Example in Do-while Loop
Php code, php scripts, php code example on do-while loop.
Do-while loop is an another form of looping in php. It repeat the codes inside the do-while loop once and loop it once again if the condition on the "while" is met. To understand more about do-while loop, please see the php code example below.
Note: To run and test the do-while loop php code example, you must know how to run a php code on your browser. To have a glimpse on how to run a php code on your browser please refer to the link below.
How to run a Php code on your browser using XAAMP and Notepad++
Now, let's begin!
Sample PHP Code on Do-While Loop
<?php $sum = 0; $product=1; $num = 0; do { $num++; echo $sum. " + ". $num. " is equal to: "; $sum = $sum + $num ; echo $sum."<br />"; }while ($num!=10); echo "<br />"; echo "The Total sum of the numbers1 to 10 is: ". $sum; ?>
Sample Output of the Do-While Loop
Guide for Beginners in PHP Programming on how to run the code above
To provide more clarification to every beginners in php programming, here is the step by step guide that you must follow to be able to run the code. This is a summary of the link above. But if you want to have a picture guide on every step, please feel free to visit the link I provided above.
1. Install XAAMP and Notepad++ in your computer.
2. To run the code, open the Xaamp and run the Apache and My SQL by checking the check box on the XAAMP interface.
3. Copy and paste the code above to notepad++ and save it to the drive where you installed your XAAMP, look for xaamp folder, click it and open the htdocs folder, and finally save your file there. I suggest that you save the file with the filename dowhileloop.php.
4. Then, go to your browser and type this on the address bar: localhost/dowhileloop.php The browser will give you the output similar to the output above.
Other PHP Sample Codes and Tutorials
- How to become a PHP Developer: Learn and Earn
- Steps on How to Program in PHP: A Beginner's Guide on PHP Programming-Part 1
- How to run PHP Code or PHP Scripts and See the Result on Your Browser
- HTML Basics: Learn The Basics of HTML and Create Your Own Webpage on Your Browser
- PHP Sample Codes On Function:How to make Function in PHP
- PHP Code Example on Associative Array and Multidimensional Array
- PHP Code Example on Numeric Array
- PHP code Example for if statement
- PHP Code Example for if-else Statement With Notepad++
- PHP Code Example on if else-if Statement
- PHP Code Example on Switch Statement:Making Choice and Cases
- PHP Code Example on While Loop
- PHP Code Example on Do-while Loop
- PHP Code Example on Foreach Loop and For Loop