I feel a for loop with the following syntax:
for i in [1..30] 2 {
println(i)
}
looks cleaner
is more readable
involves less typing
than the archaic C-style for loop.
few more examples:
// counter decrement
for i in [44..22] -2 {
println(i)
}
// step omitted
for i in [1..100] {
println(i)
}
// side-by-side
for i in [1..30] 2 {
println(i)
}
for i := 1; i < 30; i += 2 {
println(i)
}
// it took me 24 minutes just to type the above loop
for i in [1..30] 2 {
println(i)
}
This doesn't make sense at all.
for i := 1; i < 30; i += 2 {// it took me 24 minutes just to type the above loop
But in that time you learned a useful V programming construct ;-)
for i in 0..30 already works, and extended range are already discussed in #4933 (but, to be honest, it's most unlikely that they will be implemented in the language)
If you want these types of ranges then just my range library https://github.com/Delta456/range
BTW I've made #5949 to document range for.
for i in [1..30] 2 { println(i) }This doesn't make sense at all.
In what way does it not make sense, please elaborate?
@jalelegenda [1..30] in V is array slicing and 2 which is step but it seems to be unreadable.
@jalelegenda
In what way is a C-style for loop unclear? It's clearer to me than your suggestion.
If you're concerned about typing less, you should make use of a text editor that supports creating snippets.
Most helpful comment
for i in 0..30already works, and extended range are already discussed in #4933 (but, to be honest, it's most unlikely that they will be implemented in the language)