# Proposal: Allow variable assignments inside loop headers

**URL:** https://discourse.julialang.org/t/proposal-allow-variable-assignments-inside-loop-headers/11005
**Category:** Internals & Design
**Tags:** proposal
**Created:** [May 18, 2018, 11:24pm UTC](https://discourse.julialang.org/t/proposal-allow-variable-assignments-inside-loop-headers/11005 "2018-05-18T23:24:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Robert\_Honig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robert_honig/32/4930_2.png) [@Robert\_Honig](https://discourse.julialang.org/u/Robert_Honig)
#### Post date: [May 18, 2018, 11:24pm UTC](https://discourse.julialang.org/t/proposal-allow-variable-assignments-inside-loop-headers/11005/1 "2018-05-18T23:24:37Z")

</div>

Occasionally, I want to write loops like the following:

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

```

In julia 0.6.2, this throws the following error:

```julia
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?

---

<div class="post-metadata">

### Author: ![yurivish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yurivish/32/307_2.png) [@yurivish](https://discourse.julialang.org/u/yurivish)
#### Post date: [May 18, 2018, 11:42pm UTC](https://discourse.julialang.org/t/proposal-allow-variable-assignments-inside-loop-headers/11005/2 "2018-05-18T23:42:28Z")

</div>

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

```julia
julia> foo = 2
2

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

```

---

<div class="post-metadata">

### Author: ![Robert\_Honig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robert_honig/32/4930_2.png) [@Robert\_Honig](https://discourse.julialang.org/u/Robert_Honig)
#### Post date: [May 19, 2018, 10:46am UTC](https://discourse.julialang.org/t/proposal-allow-variable-assignments-inside-loop-headers/11005/3 "2018-05-19T10:46:19Z")

</div>

Whoops, yeah, silly mistake 🙂  
Thanks @yurivish!
