Julia: Reverse Range ?

Created on 8 Feb 2013  路  2Comments  路  Source: JuliaLang/julia

Maybe would be great if, for example, 3:1 generates a reverse range ( 3 2 1 )

julia> for i in 1:3
       println(i)
       end
1
2
3

julia> for i in 3:1
       println(i)
       end

Most helpful comment

You can do 3:-1:1 and get that. It can be convenient that the loop doesn't run for 3:1. If you want it to run from n to 3 then if n>3 the loop just doesn't run instead of reversing.

All 2 comments

You can do 3:-1:1 and get that. It can be convenient that the loop doesn't run for 3:1. If you want it to run from n to 3 then if n>3 the loop just doesn't run instead of reversing.

Thanks!! I forget about the each field.

Was this page helpful?
0 / 5 - 0 ratings