-
Notifications
You must be signed in to change notification settings - Fork 0
/
for.php
45 lines (30 loc) · 800 Bytes
/
for.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
//Control Structure exercise.
//Alex Zuniga
// Prompt user for a starting number
do {
fwrite(STDOUT, "Enter a Starting Number please.\n");
$starting = trim(fgets(STDIN));
} while (!is_numeric($starting));
//Entering second number
do {
fwrite(STDOUT, "Enter a Ending Number please.\n");
$ending = trim(fgets(STDIN));
} while (!is_numeric($ending));
// setting the increment
fwrite(STDOUT, "Excellent! Now choose an number to count by. ");
$increment = trim(fgets(STDIN));
if ($increment == "") {
$increment = 1;
}
if ($starting < $ending) {
for ($display = $starting; $display <= $ending; $display += $increment) {
echo "$display\n";
}
}
elseif ($starting > $ending) {
for ($display = $starting; $display >= $ending; $display -= $increment) {
echo "$display\n";
}
}
?>