PoPL/04_semantics_and_running/examples/loop-sum.ph

19 lines
311 B
Perl

var nn = 1'000'000'000
var count = 0
var sum = 0
function Func{ second_number[int] } return int
is
(second_number + 3) * 5
end function
(% Calculate sum with a loop %)
do
do
sum = sum + Func(count),
count = count + 1
until nn < count
unless nn = 0 done,
print "Sum from 0 to" & nn & "is" & sum