2019-09-22 01:59:48 +04:00
|
|
|
// Test while loops in PascaLIGO
|
|
|
|
|
2019-05-13 00:56:22 +04:00
|
|
|
function counter (var n : nat) : nat is block {
|
|
|
|
var i : nat := 0n ;
|
|
|
|
while (i < n) block {
|
|
|
|
i := i + 1n ;
|
|
|
|
}
|
|
|
|
} with i
|
|
|
|
|
2019-09-25 02:47:04 +04:00
|
|
|
function while_sum (var n : nat) : nat is block {
|
2019-05-13 00:56:22 +04:00
|
|
|
var i : nat := 0n ;
|
|
|
|
var r : nat := 0n ;
|
|
|
|
while (i < n) block {
|
|
|
|
i := i + 1n ;
|
|
|
|
r := r + i ;
|
|
|
|
}
|
|
|
|
} with r
|
|
|
|
|
2019-10-11 19:41:26 +04:00
|
|
|
function for_sum (var n : nat) : nat is block {
|
|
|
|
for i := 1 to 100 step 1
|
2019-09-25 02:47:04 +04:00
|
|
|
begin
|
2019-10-11 19:41:26 +04:00
|
|
|
n := n + 1n ;
|
2019-09-25 02:47:04 +04:00
|
|
|
end }
|
2019-10-11 19:41:26 +04:00
|
|
|
with n
|
2019-09-25 02:47:04 +04:00
|
|
|
|
2019-05-13 00:56:22 +04:00
|
|
|
function dummy (const n : nat) : nat is block {
|
|
|
|
while (False) block { skip }
|
|
|
|
} with n
|