mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 06:08:41 +01:00
Add continue statement (#822)
Note that documentation is still required.
This commit is contained in:
9
test/language/continue/closure_in_for.wren
Normal file
9
test/language/continue/closure_in_for.wren
Normal file
@ -0,0 +1,9 @@
|
||||
var f
|
||||
for (i in [1, 2, 3]) {
|
||||
var j = 4
|
||||
f = Fn.new { System.print(i + j) }
|
||||
continue
|
||||
}
|
||||
|
||||
f.call()
|
||||
// expect: 7
|
||||
9
test/language/continue/closure_in_while.wren
Normal file
9
test/language/continue/closure_in_while.wren
Normal file
@ -0,0 +1,9 @@
|
||||
var f
|
||||
while (f == null) {
|
||||
var i = "i"
|
||||
f = Fn.new { System.print(i) }
|
||||
continue
|
||||
}
|
||||
|
||||
f.call()
|
||||
// expect: i
|
||||
20
test/language/continue/exit_local_scopes.wren
Normal file
20
test/language/continue/exit_local_scopes.wren
Normal file
@ -0,0 +1,20 @@
|
||||
for (i in 0..5) {
|
||||
{
|
||||
var a = "a"
|
||||
{
|
||||
var b = "b"
|
||||
{
|
||||
var c = "c"
|
||||
if (i == 1) continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.print(i)
|
||||
}
|
||||
|
||||
// expect: 0
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
// expect: 4
|
||||
// expect: 5
|
||||
12
test/language/continue/in_for_loop.wren
Normal file
12
test/language/continue/in_for_loop.wren
Normal file
@ -0,0 +1,12 @@
|
||||
for (i in [1, 2, 3, 4, 5]) {
|
||||
System.print(i)
|
||||
if (i > 2) continue
|
||||
System.print(i)
|
||||
}
|
||||
// expect: 1
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
// expect: 4
|
||||
// expect: 5
|
||||
7
test/language/continue/in_function_in_loop.wren
Normal file
7
test/language/continue/in_function_in_loop.wren
Normal file
@ -0,0 +1,7 @@
|
||||
var done = false
|
||||
while (!done) {
|
||||
Fn.new {
|
||||
continue // expect error
|
||||
}
|
||||
done = true
|
||||
}
|
||||
9
test/language/continue/in_method_in_loop.wren
Normal file
9
test/language/continue/in_method_in_loop.wren
Normal file
@ -0,0 +1,9 @@
|
||||
var done = false
|
||||
while (!done) {
|
||||
class Foo {
|
||||
method {
|
||||
continue // expect error
|
||||
}
|
||||
}
|
||||
done = true
|
||||
}
|
||||
12
test/language/continue/in_while_loop.wren
Normal file
12
test/language/continue/in_while_loop.wren
Normal file
@ -0,0 +1,12 @@
|
||||
var i = 0
|
||||
while (true) {
|
||||
i = i + 1
|
||||
System.print(i)
|
||||
if (i <= 2) continue
|
||||
System.print(i)
|
||||
break
|
||||
}
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
// expect: 3
|
||||
17
test/language/continue/nested_for_loop.wren
Normal file
17
test/language/continue/nested_for_loop.wren
Normal file
@ -0,0 +1,17 @@
|
||||
for (i in 0..2) {
|
||||
System.print("outer %(i)")
|
||||
if (i == 1) continue
|
||||
|
||||
for (j in 0..2) {
|
||||
if (j == 1) continue
|
||||
System.print("inner %(j)")
|
||||
}
|
||||
}
|
||||
|
||||
// expect: outer 0
|
||||
// expect: inner 0
|
||||
// expect: inner 2
|
||||
// expect: outer 1
|
||||
// expect: outer 2
|
||||
// expect: inner 0
|
||||
// expect: inner 2
|
||||
23
test/language/continue/nested_while_loop.wren
Normal file
23
test/language/continue/nested_while_loop.wren
Normal file
@ -0,0 +1,23 @@
|
||||
var i = 0
|
||||
while (i <= 2) {
|
||||
i = i + 1
|
||||
|
||||
System.print("outer %(i)")
|
||||
if (i == 2) continue
|
||||
|
||||
var j = 0
|
||||
while (j <= 2) {
|
||||
j = j + 1
|
||||
|
||||
if(j == 2) continue
|
||||
System.print("inner %(j)")
|
||||
}
|
||||
}
|
||||
|
||||
// expect: outer 1
|
||||
// expect: inner 1
|
||||
// expect: inner 3
|
||||
// expect: outer 2
|
||||
// expect: outer 3
|
||||
// expect: inner 1
|
||||
// expect: inner 3
|
||||
1
test/language/continue/outside_loop.wren
Normal file
1
test/language/continue/outside_loop.wren
Normal file
@ -0,0 +1 @@
|
||||
continue // expect error
|
||||
Reference in New Issue
Block a user