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?
julia> a=1
1
julia> while (a=a+1) < 3
println(a)
end
2
1 Like
Or, for a more complete example:
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
4 Likes
I think it looks better (and more similar to Java) with
a += 1
here.
1 Like
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).
1 Like