| Do While Loops In Php |
This tutorial is for Do While Loop.Now we had looked while loopsthat basically count to 10 and prints hello each time it is incremented. Do while loop is very similar to while loop,only a minor difference is that we don’t check whether condition is true or false or we don’t evaluate condition in start. Do while loop always runs the loop once.
Code for Do While Loop (Screenshot1):-
1
2
3
4
5
6
7
8
9
| <?php//counter = 1;do {echo 'This will ALWAYS show.'}while(0)?> |
Output(Screenshot2):-
In this example we are using “do” keyword that will not check conditions but will perform whatever we tell to do and after that in while loop it will check condition. In above example, we have echo out in do loop “This will ALWAYS show” and in while statement we have false that condition.
Code for Do while loop (Screenshot3):-
1
2
3
4
5
6
7
8
9
| <?php$counter = 1;do {echo 'This will ALWAYS show once.<br>';$counter++;}while ($counter<=10)?> |
Output (Screenshot4):-
In this example we are doing same thing as we did in while loops Examples .In this we are echoing out “This will ALWAYS show” 10 times where we set counter to start with value 1 and incremented it upto value 10. If while loop condition get false it will always echo it out once by do loop. The main aim of using Do While Loop is that as it name refers it will first echo out once any statement/process declared inside “do statement” and only after executing that part itwill move for executing “do statement” further on the basis of declared conditions in “while statement”.
Read More Extra Tutorials
No comments:
Post a Comment