VOOZH about

URL: https://www.geeksforgeeks.org/php/php-while-loop/

⇱ PHP while Loop - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

PHP while Loop

Last Updated : 22 Aug, 2022

The while loop is the simple loop that executes nested statements repeatedly while the expression value is true. The expression is checked every time at the beginning of the loop, and if the expression evaluates to true then the loop is executed otherwise loop is terminated.

Flowchart of While Loop:

👁 Image
 

Syntax:

while (if the condition is true) {
 // Code is executed
}

Example 1: This example uses a while loop to display numbers.


Output
10
12
14
16
18

while-endWhile loop:

Syntax:

while (if the condition is true):
 // Code is executed
 ...
endwhile;

Example 2: This example uses while and endwhile to display the numbers.


Output
10
12
14
16
18

Reference: https://www.php.net/manual/en/control-structures.while.php

Comment
Article Tags: