# While loop

**URL:** <https://discourse.julialang.org/t/while-loop/39282>\
**Category:** New to Julia\
**Tags:** loops\
**Created:** [May 11, 2020, 1:03pm UTC](https://discourse.julialang.org/t/while-loop/39282 "2020-05-11T13:03:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jul](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Jul](https://discourse.julialang.org/u/Jul)\
**Post date:** [May 11, 2020, 1:03pm UTC](https://discourse.julialang.org/t/while-loop/39282/1 "2020-05-11T13:03:44Z")

</div>

Hello, I’m trying to rewrite some old java code to julia and I’ve problem with whlie loop. In java I was while(++a \< b && c\>d) and here I see that ++ is “not a unuary operator”. Is it possible to create this kind of compound loop in Julia?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [May 11, 2020, 1:16pm UTC](https://discourse.julialang.org/t/while-loop/39282/2 "2020-05-11T13:16:29Z")

</div>

```julia
julia> a=1
1

julia> while (a=a+1) < 3
       println(a)
       end
2

```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 11, 2020, 2:18pm UTC](https://discourse.julialang.org/t/while-loop/39282/3 "2020-05-11T14:18:39Z")

</div>

Or, for a more complete example:

```julia
function test()
    a = 0
    b = 5
    c = 10
    d = 1
    while (a += 1) < b && c > d
        c -= 1
        @show (a, b, c, d)
    end
end

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [May 11, 2020, 2:46pm UTC](https://discourse.julialang.org/t/while-loop/39282/5 "2020-05-11T14:46:18Z")

</div>

> [@Henrique\_Becker](#):
>
> `(a = a + 1)`

I think it looks better (and more similar to Java) with

```julia
a += 1

```

here.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 11, 2020, 2:50pm UTC](https://discourse.julialang.org/t/while-loop/39282/6 "2020-05-11T14:50:03Z")

</div>

Fixed. I initially tried with `a += 1` but it failed, now I see it was just because I forgot the parenthesis around the assignment when I used the `+=` operator (and automatically wrote them when changed the expanded form).
