For loops!

This commit is contained in:
Bob Nystrom
2013-12-24 21:04:11 -08:00
parent 1e0401bfc1
commit e6e7b2594c
18 changed files with 404 additions and 163 deletions
+13
View File
@@ -0,0 +1,13 @@
var list = []
var i = 1
while (i < 4) {
var j = i + 1
list.add(fn IO.write(j))
i = i + 1
}
for (f in list) f.call
// expect: 2
// expect: 3
// expect: 4
+26
View File
@@ -0,0 +1,26 @@
// Single-expression body.
var c = 0
while (c < 3) IO.write(c = c + 1)
// expect: 1
// expect: 2
// expect: 3
// Block body.
var a = 0
while (a < 3) {
IO.write(a)
a = a + 1
}
// expect: 0
// expect: 1
// expect: 2
// Newline after "while".
var d = 0
while
(d < 3) IO.write(d = d + 1)
// expect: 1
// expect: 2
// expect: 3
// TODO: Close over variable in body.