Proposal: Allow variable assignments inside loop headers

proposal

#1

Occasionally, I want to write loops like the following:

foo = 2
while foo^=2 < 32
    println(foo)
end

In julia 0.6.2, this throws the following error:

syntax: invalid identifier name "^="

Assignments return the assigned object and it would be great if we could take use of this behavior in loops (or other control flow expressions).

What do others think?


#2

Does this do what you’d like? The error message seems unclear to me, but the crux of the problem is precedence:

julia> foo = 2
2

julia> while (foo ^= 2) < 32
           @show foo
end
foo = 4
foo = 16

#3

Whoops, yeah, silly mistake :slight_smile:
Thanks @yurivish!