Added do-while loop statement (#21611)
* Added do-while loop statement * moved links to bottom, changed to markdown style linkspull/21728/head^2
parent
b9b76e8f43
commit
68d00ec899
|
@ -1,7 +1,8 @@
|
||||||
---
|
---
|
||||||
title: While Loop
|
title: While Loop
|
||||||
---
|
---
|
||||||
## While Loops
|
|
||||||
|
## While Loop
|
||||||
A `while` loop executes statements within the loop as long as the loops condition is met.
|
A `while` loop executes statements within the loop as long as the loops condition is met.
|
||||||
|
|
||||||
### Syntax:
|
### Syntax:
|
||||||
|
@ -16,5 +17,20 @@ while ($x < 11) {
|
||||||
|
|
||||||
**Note:** The block code must have a statement that changes or increments the condition. Otherwise an infinite loop could result.
|
**Note:** The block code must have a statement that changes or increments the condition. Otherwise an infinite loop could result.
|
||||||
|
|
||||||
|
|
||||||
|
Another loop statement is `do...while` where you execute your code at least once.
|
||||||
|
|
||||||
|
### Syntax
|
||||||
|
```php
|
||||||
|
$x = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
++$x;
|
||||||
|
} while ($x < 11);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** Same as the `while` block, this should have a statement that changes, otherwise an infinite loop could result.
|
||||||
|
|
||||||
### More Information:
|
### More Information:
|
||||||
<a href='http://php.net/manual/en/control-structures.while.php' target='_blank' rel='nofollow'>PHP While Loop</a>
|
- [PHP While Loop](http://php.net/manual/en/control-structures.while.php)
|
||||||
|
- [PHP Do-While Loop](http://php.net/manual/en/control-structures.do.while.php)
|
||||||
|
|
Loading…
Reference in New Issue