blob: 62cee15c7d354e2e9b022b8312c78a95717b7f37 (
plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
<?php
old_function a (
echo "hey\n";
);
function b($i)
{
echo "$i\n";
}
function c($i,$j)
{
echo "Counting from $i to $j\n";
for ($k=$i; $k<=$j; $k++) {
echo "$k\n";
}
}
a();
b("blah");
a();
b("blah","blah");
c(7,14);
a();
old_function factorial $n (
if ($n==0 || $n==1) {
return 1;
} else {
return factorial($n-1)*$n;
}
);
function factorial2($start, $n)
{
if ($n<=$start) {
return $start;
} else {
return factorial2($start,$n-1)*$n;
}
}
for ($k=0; $k<10; $k++) {
for ($i=0; $i<=10; $i++) {
$n=factorial($i);
echo "factorial($i) = $n\n";
}
}
echo "and now, from a function...\n";
old_function call_fact (
echo "(it should break at 5...)\n";
for ($i=0; $i<=10; $i++) {
if ($i == 5) break;
$n=factorial($i);
echo "factorial($i) = $n\n";
}
);
old_function return4 ( return 4; );
old_function return7 ( return 7; );
for ($k=0; $k<10; $k++) {
call_fact();
}
echo "------\n";
$result = factorial(factorial(3));
echo "$result\n";
$result=factorial2(return4(),return7());
echo "$result\n";
old_function andi $i, $j (
for ($k=$i ; $k<=$j ; $k++) {
if ($k >5) continue;
echo "$k\n";
}
);
andi (3,10);
|