-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfor.php
executable file
·61 lines (54 loc) · 1.26 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="for.php" method="post">
<label for="">Enter a number to count down from</label>
<input type="text" name="counter">
<input type="submit" value="run">
</form>
</body>
</html>
<?php
// for loop = repeat some code a certain # of times
// there are three optional statements - counter - condition - increment/decrement counter
// for ($i = 1; $i <= 5; $i++) {
// echo "{$i} <br>";
// }
// for ($i = 10; $i > 0; $i--) {
// echo "{$i} <br>";
// }
$counter = $_POST["counter"];
// count up
// if ($counter > 0)
// {
// for ($i=0;$i<=$counter;$i++)
// {
// echo "{$i} <br>";
// }
// }
// else {
// for ($i=0;$i>=$counter;$i--)
// {
// echo "{$i} <br>";
// }
// }
//count down
if ($counter > 0)
{
for ($i = $counter; $i >= 0;$i--)
{
echo "{$i} <br>";
}
}
else {
for ($i = $counter; $i <= 0; $i++)
{
echo "{$i} <br>";
}
}
?>