Make ProgressMeter description display depends on a for-loop variable

The following works well:

using ProgressMeter
@showprogress dt=1 desc="Computing ..." for c in 1:100_000
    # Some computing
end

However, I’d like the description to display some string that depends on c:

using ProgressMeter
@showprogress dt=1 desc="Computing $c..." for c in 1:100_000 # this throws an error
    # Some computing
end

Or ideally:

using ProgressMeter
@showprogress dt=1 desc="Computing $(c % 100 == 0 ? c : "")..." for c in 1:100_000  # this throws an error
    # Some computing
end

Is that easily achievable?

Alright, it was easy actually:

using ProgressMeter
n = 100_000
prog = Progress(n)
    
for c in 1:n
    next!(prog, desc="Computing $(c % 100 == 0 ? c : "")...")
    # Some computing
end
2 Likes

I think you might actually want https://github.com/timholy/ProgressMeter.jl?tab=readme-ov-file#printing-additional-information

2 Likes

For example:

let n=10^7, prog = Progress(n)
    for c in 1:n
        next!(prog, showvalues=[(:c, c)])
        # Some computing
    end
end

showprogress

You can also use an arbitrary string, e.g. next!(prog, showvalues=[("c value", c)]).

4 Likes