Two questions about Julia

This isn’t about assigning to a variable. The problem is that '' itself isn’t valid syntax. When you write 'a' that is syntax specifically for the single character a, not a string of characters. If you want to write an empty string you can do

julia> ch = ""
""

which creates an empty string. There is no definitive empty character, so '' is made to be a syntax error instead.

If you already know how to construct a reversed loop, then I’m not sure what to say. Yes, the second thing you wrote is the correct way to express a loop from last down to first.

The first thing you wrote is a loop over an empty range:

julia> length(10:1)
0

julia> length(10:-1:1)
10
8 Likes