Nesting a for loop in a while loop

I would go with:

julia> function sqrt(sets)
           repeat = Ref(true)
           count = 1
           @async while count < 5 && repeat[]
                   i = sets[count]
                   try
                       println("the square root of $i is $(i^(1/2))")
                   catch
                       println("error when tried to compute sqrt($i)")
                   finally
                       sleep(5)
                       count+=1 
                   end 
           end 
           return(repeat)
       end

Note that you cannot remove the catch and stay just with the finally, because otherwise the async thread will bubble the exception up.

2 Likes