Printing output on screen

Consider the following small example:

for i in 1:10
    println("Iteration: $(i)/10")
end

This shows up on the screen as follows:
example

In each iteration, a new line is added. Is there any way that would ensure that visually it looks like the output is printed on the same line, exactly over the previous call, but still updating? One would only see one line with Iteration: x/10, and x would keep updating.

\r moves the cursor at the beginning of the line:

for i in 1:10
    sleep(0.1)
    print("\rIteration: $(i)/10")
end

If you want nice progressbars, you can look at GitHub - timholy/ProgressMeter.jl: Progress meter for long-running computations

4 Likes