2 ms·
From "Muon by example" [0], the for loops look pretty natural/intuitive subjectively. for i := 1; i < n { temp := a a += b b = temp } > `for`
by lioeters 7y ago
From "Muon by example" [0], the for loops look pretty natural/intuitive subjectively.
for i := 1; i < n {
temp := a
a += b
b = temp
}
> `for` works mostly like in other imperative languages. For convenience, the 3rd term can be omitted; in that case, the index variable is incremented by 1 at the end of each iteration of the loop. The index variable is scoped to the loop body. The variable can be omitted if you want to use an existing index variable, e.g.: for ; i < n; i += 1 { ... }
With arrays:
for x in arr {
sum += x
}
for x, i in arr {
sum += x
}
for arr {
sum += it
}
> A secondary loop variable may be specified which holds the index of the current element. If no loop variable is specified, the name `it` is used.
[0] https://github.com/nickmqb/muon/blob/master/docs/muon_by_example.md https://github.com/nickmqb/muon/blob/master/docs/muon_by_exa...