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


	$sum = 0;
	$num = 0;
		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.


    0 of 8192 characters used
    Post Comment

    No comments yet.


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: ""