This tutorial is for Do While Loop.Now we had looked while loops that 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):-
|
Screenshot1 |
Output Screenshot2
|
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):-
|
Code for do while loops Screensot3 |
Output (Screenshot4):-
|
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 up-to 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 it will move for executing “do statement” further on the basis of declared conditions in “while statement”.
No comments:
Post a Comment
Thanks For Comment Will get you Soon..