mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Add for loops
This commit is contained in:
parent
a212dd7fd1
commit
efb99a9ed7
28 changed files with 284 additions and 21 deletions
4
test/tests/for break.ans
Normal file
4
test/tests/for break.ans
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
for(:x, range(10))
|
||||
if(x == 3)
|
||||
break!
|
||||
|{x}
|
||||
4
test/tests/for continue.ans
Normal file
4
test/tests/for continue.ans
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
for(:x, range(4))
|
||||
if(x == 3)
|
||||
continue!
|
||||
|{x}
|
||||
2
test/tests/for invalid iterator.ans
Normal file
2
test/tests/for invalid iterator.ans
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
for(:x, 42)
|
||||
|{x}
|
||||
4
test/tests/for list.ans
Normal file
4
test/tests/for list.ans
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
:l = *[7,96,"a",3]
|
||||
|
||||
for(:x, l)
|
||||
|{x}
|
||||
27
test/tests/for range.ans
Normal file
27
test/tests/for range.ans
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
|-
|
||||
for(:x, range(5))
|
||||
|{x}
|
||||
|
||||
|-
|
||||
for(:y, range(2, 7))
|
||||
|{y}
|
||||
|
||||
|-
|
||||
for(:z, range(2, 7, 3))
|
||||
|{z}
|
||||
|
||||
|-
|
||||
for(:x, range(4, 0, -1))
|
||||
|{x}
|
||||
|
||||
|-
|
||||
for(:x, range(4, 8, -1))
|
||||
|{x}
|
||||
|
||||
|-
|
||||
for(:x, range(8, 4))
|
||||
|{x}
|
||||
|
||||
|-
|
||||
for(:x, range(4, 4))
|
||||
|{x}
|
||||
7
test/tests/for struct.ans
Normal file
7
test/tests/for struct.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
:s = { "a":"b", 6:"c", 98:5, true:3 }
|
||||
:t = *s
|
||||
|
||||
/* struct iteration is non deterministic, too lazy to sort, so we check if we have 4 key that each appear at most once */
|
||||
for(:k, s)
|
||||
|{t!has(k)}|
|
||||
t(k) = ()
|
||||
6
test/tests/for table.ans
Normal file
6
test/tests/for table.ans
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
:s = *{ "a":"b", 6:"c", 98:5, true:3 }
|
||||
|
||||
/* struct iteration is non deterministic, too lazy to sort, so we check if we have 4 key that each appear at most once */
|
||||
for(:k, s)
|
||||
|{s!has(k)}|
|
||||
s(k) = ()
|
||||
4
test/tests/for tuple.ans
Normal file
4
test/tests/for tuple.ans
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
:t = [2,5,7,1,8]
|
||||
|
||||
for(:x, t)
|
||||
|{x}
|
||||
Loading…
Add table
Add a link
Reference in a new issue