for loops

This commit is contained in:
2026-06-22 20:11:18 +02:00
parent 380b5943b3
commit 27f42dd253
15 changed files with 1369 additions and 22 deletions
+52
View File
@@ -0,0 +1,52 @@
# Milestone 5: ranges and sequence for loops.
pass :: func(value int) int {
return value
}
main :: func() i32 {
total i32 = 0
items [3]mut i32 = [1, 2, 3]
for items |item, index| {
total = total + item
_ = index
}
for (&items) |@item| {
item^ = item^ + 1
}
view []mut i32 = (&items)[..]
for view |@item, index| {
item^ = item^ + 1
_ = index
}
for view |item| {
total = total + item
}
for [4, 5] |item| {
total = total + item
}
for "ab" |byte| {
_ = byte
total = total + 1
}
for 0..4 |value| {
total = total + value
}
for 1..=3 |value| {
total = total + value
}
once :: 0..1
for pass(once) |value| {
_ = value
total = total + 1
}
return total
}