TDT4205/exercises/06/vslc/vsl_programs/ps6-codegen2/while_test.vsl

57 lines
796 B
Plaintext
Raw Normal View History

2022-04-10 15:55:56 +02:00
// This program is a simple test of while loops, counting down from 19 to 0
// and skipping 10 (if continue is implemented)
func while_test ()
begin
2022-04-22 18:40:36 +02:00
var a, b
2022-04-10 15:55:56 +02:00
a := 20
2022-04-22 18:40:36 +02:00
b := test_while()
2022-04-10 15:55:56 +02:00
print a
2022-04-22 18:40:36 +02:00
2022-04-10 15:55:56 +02:00
if a > 0 then print "foobar"
while a > 0 do
begin
if a = 10 then
begin
a -= 1
print "Skip..."
continue
end
else
a -= 1
print a
end
2022-04-22 18:40:36 +02:00
return 0
end
func test_while()
begin
var n, m
n := 4
m := 21
while n > 0 do
begin
n -= 1
if n = 2 then
continue
while m > 0 do
begin
m -= 1
if m = 10 then
continue
print n, m
end
end
2022-04-10 15:55:56 +02:00
return 0
end