Looping Statements in PHP

In this tutorial we will learn Looping Statements in PHP. Looping statements help us to run a piece of code again and again. For example you want to show 1 to 100 on your page. IN normal case you have to write echo 100 time with number to show 1 to 100 on web page. But with the help of loop you can do this task very easily by writing echo for only once. There are three looping statements in PHP.

  • for loop
  • while loop
  • do while loop

Looping Statements in PHP


Now we will learn each looping statement in detail.

for loop: for loop is used to run a piece of code for certain number of times. Check this example. In this example we will write 1 to 10 using for loop.

Example





while loop: If you want to run a piece of code again and again until certain condition is true. Then while would so helpful to you. Here is Example of while loop.

Example





do while loop: do while loop is same like while loop but there is a small difference. In case of false condition in first iteration of while loop, Body of while loop would not run. But in case of do while loop. It will run. because it check condition after running the body of loop. Check this example.

Example







Share this tutorial with your friends on your social Media..

Looping Statements in PHP Looping Statements in PHP Looping Statements in PHP Looping Statements in PHP



Now You Can Follow All These Tutorials on Your Android Mobile Just Download This App.


Owlbuddy.com