1
0
Fork 0
forked from fun/fun

Array iteration.

This commit is contained in:
Johannes Findeisen 2025-09-15 03:03:00 +02:00
commit 879801cbfc
2 changed files with 259 additions and 103 deletions

30
examples/arrays_iter.fun Normal file
View file

@ -0,0 +1,30 @@
// for-in over an array literal
for x in [1, 2, 3]
print(x) // prints: 1, then 2, then 3
// for-in over a named array
arr = [10, 20, 30]
for x in arr
print(x) // prints: 10, then 20, then 30
// nested arrays: iterate rows, then elements
matrix = [[1, 2], [3, 4]]
for row in matrix
print(row) // prints: [1, 2] then [3, 4]
for v in row
print(v) // prints: 1, 2, 3, 4
// iterate over an array expression (concatenation)
for v in arr + [40, 50]
print(v) // prints: 10, 20, 30, 40, 50
// iterate over a slice (end = -1 means till the end)
for v in arr[1:-1]
print(v) // prints: 20, 30
// iterate over a function result
fun make()
return [7, 9, 11]
for v in make()
print(v) // prints: 7, 9, 11