PHP While Statement
PHP While Statement
lecture 11
SE-1st Year
Topics Discussed
PHP Loops
While loop statements
When to use while loops
Types
How it works
Syntax
Practical Examples
Summary
PHP Loops
Often when you write code, you want the same
block of code to run over and over again a certain
number of times. So, instead of adding several
almost equal code-lines in a script, we can use
loops.
Loops are used to execute the same block of code
again and again, as long as a certain condition is
true.
The while loop statement
The while statement will execute a block of code
if and as long as a test expression is true.
If the test expression is true then the code block
will be executed. After the code has executed the
test expression will again be evaluated and the
loop will continue until the test expression is
found to be false
When to use while loops
While loops are used to execute a block of code
until a certain condition becomes true.
You can use a while loop to read records returned
from a database query.
Types of while loops