diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-30 18:16:45 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-30 18:16:45 +0800 |
| commit | 8c3d786157ec7fef3072feac55c2d5450800568b (patch) | |
| tree | 6c44a85e02abe74e6c3ccc4d7393ba8784c49ce7 /spec/inputs/test/continue_spec.yue | |
| parent | 220a10d0df3341b2bbb0beaee4f90d6480e7ae38 (diff) | |
| download | yuescript-main.tar.gz yuescript-main.tar.bz2 yuescript-main.zip | |
Diffstat (limited to 'spec/inputs/test/continue_spec.yue')
| -rw-r--r-- | spec/inputs/test/continue_spec.yue | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/inputs/test/continue_spec.yue b/spec/inputs/test/continue_spec.yue new file mode 100644 index 0000000..bf4e839 --- /dev/null +++ b/spec/inputs/test/continue_spec.yue | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | describe "continue statement", -> | ||
| 2 | it "should skip odd numbers in for loop", -> | ||
| 3 | numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
| 4 | even = for n in *numbers | ||
| 5 | continue if n % 2 == 1 | ||
| 6 | n | ||
| 7 | |||
| 8 | assert.same even, {2, 4, 6, 8, 10} | ||
| 9 | |||
| 10 | it "should filter values in while loop", -> | ||
| 11 | i = 0 | ||
| 12 | result = [] | ||
| 13 | |||
| 14 | while i < 10 | ||
| 15 | i += 1 | ||
| 16 | continue if i % 3 == 0 | ||
| 17 | table.insert result, i | ||
| 18 | |||
| 19 | assert.same result, {1, 2, 4, 5, 7, 8, 10} | ||
| 20 | |||
| 21 | it "should skip with condition in loop expression", -> | ||
| 22 | items = [1, 2, 3, 4, 5] | ||
| 23 | odds = for item in *items | ||
| 24 | continue if item % 2 == 0 | ||
| 25 | item | ||
| 26 | |||
| 27 | assert.same odds, {1, 3, 5} | ||
| 28 | |||
| 29 | it "should work with nested loops", -> | ||
| 30 | result = [] | ||
| 31 | |||
| 32 | for i = 1, 5 | ||
| 33 | for j = 1, 5 | ||
| 34 | continue if i == j | ||
| 35 | table.insert result, {i, j} | ||
| 36 | |||
| 37 | assert.same #result, 20 | ||
