-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path05_loops.php
51 lines (39 loc) · 940 Bytes
/
05_loops.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Eng: initialize(i=1); condition(i<=10); and increment(i++) || Pt: incremento;
* Eng: initialize(i=1); condition(i<=10); and decrement(i--) || Pt: decremento;
*/
echo "<hr>For loop: ";
/** For loop **/
for ($i=1; $i < 10; $i++) {
var_dump($i);
}
echo "<hr>while loop: ";
/** while loop **/
$i=1;
$limit = 10;
while ($i <= $limit) {
echo $i;
$i++;//increment(i++)
}
echo "<hr>DoWhile loop: ";
/**DoWhile loop **/
$i=1;
$limit = 10;
do {
print($i);
$i++;//increment(i++)
} while ($i <= $limit);
// echo "<hr>foreach loop, for arrays:<br>";
// /**foreach loop **/
// $posts = ['first post', 'second post', 'third post'];
// foreach ($posts as $content) {
// var_dump($content);
// }
echo "<hr>foreach loop, for arrays:<br>";
/**foreach loop **/
$posts = ['first post', 'second post', 'third post'];
foreach ($posts as $index => $content) {
echo($index+1 . " - " .$content."<br>");
}
?>