| For slice expressions, the reason for the syntax was done on purpose for the following reasons: * It's the same syntax as Go and Python, making it familiar to others who have used those languages * It allows for partial ranges e.g. `x[:]`, `x[:n]`, `x[i:]` * Partial ranges with the _two_ range expressions (a..<b and a..=b) look awful and are inconsistent: `x[..<]` `x[..=]`, `x[..<n]` `x[..=n]`, `x[i..<]` `x[i..=]` * You effectively only ever want Python/Go like semantics with slicing because Odin is a 0-index language * Ranges in Odin are only allowed in two contexts: `cases` and `for in` loops. As for C-style for loops, they are not obsolete by any stretch and any one who thinks so in think that the compiler can easily optimize a magical complex iterator without any problem. In languages without C-style for loops, you'll see people try to emulate them regardless with variables and a while loop, not just an iterator. As for syntax, where does it say "don't use it"? I really don't understand why people state things without evidence. |
In Nim, non-closure iterators are guaranteed to be inlined, so `for i in 0..<16` always compiles to what you'd write in C.
>In languages without C-style for loops, you'll see people try to emulate them regardless with variables and a while loop, not just an iterator.
There's no “emulation” going on. A C-style for loop is literally just different syntax for a while loop.