This tutorial is of While Loops. In php,why we need loops during programming ? Here we may repeat certain amount of actions for a specified amount of times.
Code for While Loop (Screenshot1):-
|
Screenshot1 |
Output (Screenshot2) :-
|
Screenshot2 |
In this example we have echoed out “Hello” by while loop.In this loop 1 evaluates true which echo out “Hello” but what if we want to echo out “Hello” 100 times! Let see example,how to echo out “Hello” for 10 times.
Code for While Loop (Screenshot3):-
|
Code for while Loops Screenshot3 |
Output (Screenshot4):-
|
Screenshot4 |
In this example, we have starter counter which initialize/starts loop and condition counter which must be less than or equal to 10 that will be incremented again and again upto the limit of condition counter and thus echo out “Hello” 10 times.
Code for While loop (Screenshot5):-
|
Screenshot5 |
Ouput (Screenshot6) :-
|
Screenshot6 |
In this example condition will false and will not display “Hello” because condition counter is greater than 10.
No comments:
Post a Comment
Thanks For Comment Will get you Soon..