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 charactera, 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 lastdown to first.
The first thing you wrote is a loop over an empty range:
It would obviously be way too breaking, but I wonder if 10:1 should be 10:-1:1 and there should be a different way to ask for the empty range starting at 10. Our reasoning is principled but I don’t think anyone new to the language understands it.
That’s a semicolon loop, essentially syntactic sugar for a while loop. The syntax does not exist in many languages, which often opt instead for foreach loops. That applies to Julia. A macro can replicate the C-style loop, but I’d probably just stick to let and while.
@DNF: R reverses ranges in this fashion and I have been bitten by that several times. @hack3rcon: Another nice thing about empty ranges is that they are valid for indexing, i.e., the following works as expected (at least that’s what I would expected, see reversed ranges above):
The loop for (int i = 10; i >= 1; i--) in C is always explicit about the step, via i++, i-- or i+=..., except that its hidden under a bit of boilerplate. I.e., the closest translations to Julia would be for i in 1:1:10 for counting up or for i in 10:-1:1 for counting down.