for loops
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user