ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Programming Languages

PHP Code Looping Example in Do-while Loop

Updated on February 22, 2013

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.


Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.