From 2447d158241aeaaf9c0b1ab21a08db7a40e5cef3 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 24 Mar 2020 10:19:30 +0800 Subject: add goto statement support. --- spec/inputs/goto.moon | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 spec/inputs/goto.moon (limited to 'spec') diff --git a/spec/inputs/goto.moon b/spec/inputs/goto.moon new file mode 100644 index 0000000..3410ca3 --- /dev/null +++ b/spec/inputs/goto.moon @@ -0,0 +1,41 @@ +do + a = 0 + ::start:: + a += 1 + goto done if a == 5 + goto start + ::done:: + +do + for z = 1, 10 for y = 1, 10 for x = 1, 10 + if x^2 + y^2 == z^2 + print 'found a Pythagorean triple:', x, y, z + goto done + ::done:: + +do + for z = 1, 10 + for y = 1, 10 for x = 1, 10 + if x^2 + y^2 == z^2 + print 'found a Pythagorean triple:', x, y, z + print 'now trying next z...' + goto zcontinue + ::zcontinue:: + +do + ::redo:: + for x = 1, 10 for y = 1, 10 + if not f x, y then goto continue + if not g x, y then goto skip + if not h x, y then goto redo + ::continue:: + ::skip:: + +do + for x in *t + if x % 2 == 0 + print 'list has even number' + goto has + print 'list lacks even number' + ::has:: + -- cgit v1.2.3-55-g6feb