PHP WHILE & DO WHILE LOOP STATEMENTS - PHP LESSON 10 STUDENTSBLOG100

Php loop statements are
  • 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:

Output:
Print Number - 1
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:

Output:
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.

Lesson 9  Previous | Main Page | Next Lesson 11

Previous
Next Post »