Php loop statements are
While Loop:
While loop will be executed if the condition given initially is true. If the condition is false, the coded inside the while loop will not be executed.
- While
- Do While
- For
- For each
While Loop:
While loop will be executed if the condition given initially is true. If the condition is false, the coded inside the while loop will not be executed.
Syntax:
Example:
Print Number - 1
Print Number - 2
Print Number - 3
Print Number - 4
Print Number - 2
Print Number - 3
Print Number - 4
Do - While Loop:
Do While loop will be executed even if the condition given initially is False. That is even If the while condition is false, the coded inside the while loop will be executed once.
Syntax:
Example:
Print Number - 10
In the above program, initially we have assigned the value for variable a as 10. Now it is entering to loop and printing the value of a. After than a's value is incremented by 1,that is now a's value is 11. Loop closed and checking the while condition. Condition is intimating that it is false.So loop stopped.If condition is true, it will be executed until the while condition is false.
No comments:
Post a Comment