Proposal: Allow variable assignments inside loop headers



Occasionally, I want to write loops like the following:

foo = 2
while foo^=2 < 32

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?


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

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


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