# Formatting assignment in function call

**URL:** <https://discourse.julialang.org/t/formatting-assignment-in-function-call/105269>\
**Category:** New to Julia\
**Created:** [October 21, 2023, 3:02pm UTC](https://discourse.julialang.org/t/formatting-assignment-in-function-call/105269 "2023-10-21T15:02:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdm204](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdm204/32/39289_2.png) [@jdm204](https://discourse.julialang.org/u/jdm204)\
**Post date:** [October 21, 2023, 3:02pm UTC](https://discourse.julialang.org/t/formatting-assignment-in-function-call/105269/1 "2023-10-21T15:02:43Z")

</div>

I assign to a variable in the condition of a while loop in this working code:

```julia
getdata() = rand() < 0.5 ? rand() : missing

function dowork()
    while !ismissing((val = getdata();))
        println(val^2)
    end
end

```

When I format the file with JuliaFormatter.format\_file(), the semicolon is removed. The code then errors with “ERROR: MethodError: no method matching ismissing(; val::Float64)”.

Should this syntax not be allowed or is this a bug in JuliaFormatter?

The versions are Julia 1.9.3, JuliaFormatter 1.0.36.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [October 21, 2023, 7:59pm UTC](https://discourse.julialang.org/t/formatting-assignment-in-function-call/105269/2 "2023-10-21T19:59:14Z")

</div>

I suspect this is a bug in the formatter or the parser that it uses. You could use this synatax instead:

```julia
while (val = getdata(); !ismissing(val))
    # body
end

```

However, I’d argue that just putting a check and break in the middle of a while true loop is clearer:

```julia
while true
    val = getdata()
    ismissing(val) && break
    # body
end

```

---

<div class="post-metadata">

**Author:** ![jdm204](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdm204/32/39289_2.png) [@jdm204](https://discourse.julialang.org/u/jdm204)\
**Post date:** [October 23, 2023, 7:27am UTC](https://discourse.julialang.org/t/formatting-assignment-in-function-call/105269/3 "2023-10-23T07:27:57Z")

</div>

Thanks Stefan, I’ve submitted an issue with JuliaFormatter.

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [May 8, 2025, 5:57am UTC](https://discourse.julialang.org/t/formatting-assignment-in-function-call/105269/4 "2025-05-08T05:57:14Z")

</div>

Just figured this out today, but this also works:

```julia
while !ismissing(local val=getdata())
    # body
end

```

Useful for short-circuiting evaluations:

```julia
isnothing(local x=foo()) || bar(x)

```
