- HubPages»
- Technology»
- Computers & Software»
- Computer Science & Programming»
- Programming Languages
PHP Code Sample Output on While Loop
PHP code, sample PHP Scripts, PHP code example on while loop
Another PHP code example for php programming. Loop in php is similar also to other programming languages. This hub will contain a sample code and a sample output on how while loop works in PHP programming.
Note.: before you continue, if you wish to learn more about php, you should know at a least, how to run a php file on your browser. If you do not know how it us done, please refer to the link below.
How to run a PHP code on your own browser using XAAMP and Notepad++
Please save the following code as whileloop.php, to avoid confusion on running this code.
PHP Code Example on While Loop
<?php $sum = 0; $product=1; $num = 0; while(!($num==10)) { $num++; $sum = $sum + $num; $product = $product * $num; } echo "The sum of the numbers from 1 to 10 is: ".$sum. "<br />"; echo "The product of the numbers from 1 to 10 is: ".$product; ?>
Sample output for whileloop.php
A Beginners' Guide on Running the code:
1. Install XAAMP and Notepad++.
2. Open XAAMP and run the Apache as well as MY SQL on the XAAMP interface.
3. Copy and paste the "php code example in while loop" in notepad++ and save on the drive where you installed the Xaamp, then look for the Xaamp folder, open it, next open the htdocs folder and php file as whileloop.php.
4. After doing that, go to your browser and type this in the address bar: localhost/whileloop.php, the sample output should be similar as the output above.
Other PHP Code Examples 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 on Switch Statement:Making Choice and Cases
- PHP code Example for if statement
- PHP Code Example on if else-if Statement
- PHP Code Example on Do-while Loop
- PHP Code Example on Foreach Loop and For Loop