-
Notifications
You must be signed in to change notification settings - Fork 0
/
loops.php
45 lines (38 loc) · 952 Bytes
/
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
<?php
//WHILE LOOP
/* $fuel = 10;
while ($fuel > 1)
{
//Keep driving
echo "There is enough fuel";
}
*/
// Well the program above crashed after I run it so I ain't running it again for now .
/*
$count = 1;
while ($count <= 12)
{
echo "$count times 12 = " . $count * 12 . "<br>";
$count ++;
}
//There is a much neater way to produce the code above which is by putting the count++ in the condition.
$value = 0;
while (++$value <= 12)
{
echo "$value times 12 = " . $value * 12 . "<br>";
}
//DO...WHILE LOOP
//The same program above but in a do...while loop.
$number = 1;
do
{
echo "$number times 12 is " . $number * 12 . "<br>";
} while (++$number <= 12);
*/
//FOR LOOP
//The same program but this time in a for loop
for ($integer = 1; $integer <= 12; ++$integer)
{
echo "$integer times 12 = " . $integer * 12 . "<br>";
}
?>