2024-06-12 11:46:11 +02:00
|
|
|
print('-- test while loop --')
|
2024-06-07 11:37:53 +02:00
|
|
|
{
|
2024-06-12 11:46:11 +02:00
|
|
|
let i := 0
|
2024-06-07 11:37:53 +02:00
|
|
|
while (i < 3) {
|
2024-06-12 11:46:11 +02:00
|
|
|
i := i + 1
|
|
|
|
print(i)
|
2024-06-07 11:37:53 +02:00
|
|
|
}
|
2024-06-12 11:46:11 +02:00
|
|
|
print(i)
|
2024-06-07 11:37:53 +02:00
|
|
|
}
|
2024-06-13 18:10:37 +02:00
|
|
|
|
|
|
|
print('-- test for loop --')
|
|
|
|
{
|
|
|
|
for (let i := 0; i < 3; i := i + 1) {
|
2024-08-27 17:04:54 +02:00
|
|
|
print(i) // prints 3 times
|
2024-06-13 18:10:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print('-- test emptier for loop --')
|
|
|
|
{
|
|
|
|
let i := 0;
|
|
|
|
for (;i < 3;) {
|
|
|
|
print('woo')
|
|
|
|
i := i + 1;
|
|
|
|
}
|
|
|
|
print('hoo')
|
|
|
|
}
|
2024-07-11 18:34:21 +02:00
|
|
|
|
|
|
|
print('-- for in loop with arrays --')
|
|
|
|
{
|
|
|
|
let arr := [1, 2, 3]
|
|
|
|
for (let i in arr) {
|
|
|
|
print(i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print('-- for in loop with arrays and keys --')
|
|
|
|
{
|
|
|
|
let arr := [1, 2, 3]
|
|
|
|
for (let k, v in arr) {
|
|
|
|
print(k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print('-- for in loop with tuples --')
|
|
|
|
{
|
|
|
|
let tup := (1, 2, 3)
|
|
|
|
for (let i in tup) {
|
|
|
|
print(i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print('-- for in loop with tuples and keys --')
|
|
|
|
{
|
|
|
|
let tup := (1, 2, 3)
|
|
|
|
for (let k, v in tup) {
|
|
|
|
print(k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
print('-- for in loop with dicts --')
|
|
|
|
{
|
|
|
|
let obj := {'first': 'v1', 'second': 'v2', 'third': 'v3'}
|
|
|
|
for (let i in obj) {
|
|
|
|
print(i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print('-- for in loop with dicts and keys --')
|
|
|
|
{
|
|
|
|
let obj := {'first': 'v1', 'second': 'v2', 'third': 'v3'}
|
|
|
|
for (let k, v in obj) {
|
|
|
|
print(k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|