basic for loop + examples -> era3

This commit is contained in:
Neemek 2026-07-13 10:01:13 +02:00
parent dd7af341a3
commit 0bc8b2ef55
Signed by: neemek
GPG key ID: 84FFE4D7D40AB25E
24 changed files with 222 additions and 201 deletions

View file

@ -1,51 +1,47 @@
# Empty list
write([])
println([])
# List with items
write([3, 1, 4, 1, 5, 9, 2, 6, 5])
println([3, 1, 4, 1, 5, 9, 2, 6, 5])
# List with items of different types
write(["", "私はかっこいいです。", true, nil, nil, 1, 2])
println(["", "私はかっこいいです。", true, nil, nil, 1, 2])
a := []
a = a.append(1)
a = a.append(2)
a = a + [1]
a = a + [2]
write(a)
println(a)
list := []
n := 0
x := 0
while n < 100 {
for n in 0..100 {
x = x + 2*n + 1
list = list.append(x)
n = n + 1
list = list + [x]
}
write(list)
write(list.map(func(a) {
println(list)
println(list.map(func(a) {
return a - 1
}))
write(list.length())
write(list.at(69))
println(list.length())
println(list.at(69))
other := []
a := 1
while a <= 10 {
for a in 0..=10 {
other = other.append(a)
a = a + 1
}
sum := other.reduce(func(tot, x) {
return tot + x
}, 0)
write(sum)
println(sum)
assert(sum == a*(a-1)/2)