3 ms·
Moun’s for loops make me angry.
by duckqlz 7y ago
Moun’s for loops make me angry.
- all2 7y agoCan you expand on this?
- saagarjha 7y agoI’m also confused; Muon’s loop syntax and semantics looks nothing out of the ordinary except that it allows omitting expressions…
- lioeters 7y agoFrom "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...