Sunday, January 24, 2016

PHP DO WHILE LOOP: Display Numbers Using Do While Loop

PHP for loops execute a block of code a specified number of times. There are four (4) types of loops in PHP. The for loop, foreach loop, do while loop and the while loop. In this tutorial, we will be focusing on the while loop which I often used in creating iterations to save code and memory space.

The Do While loop executes the body of the loop before checking for the condition. Unlike the while loop wherein testing the condition is done first and then executes the statement of the body if  its false. Again, a condition always returns a boolean value which is either true or false.

PHP Code Do While Loop

echo $i;

Output Do while loop

Starting point is set in the $i  and will execute the code inside the loop which will display the value of $i which is one and then it will be incremented by one (1). The while statement in the will check if the value of $i is less than 10. If it's true, then it will  execute the loop again until the condition returns a false value.

That would be all. Thank you for visiting and hope this helps you. Feel free to leave a comment below for any questions. I got some other articles related to php in blog and even related to loops.

PHP DO WHILE LOOP: Display Numbers Using Do While Loop

No comments:

Post a Comment