On Sat, Feb 7, 2015 at 3:12 PM, Kevin Squire <[email protected]> wrote:
> I have mixed feelings, as I'm somehow one of those people who frequently > breaks out of loops and wants to know the value of the variable at the last > iteration. +1000000 It's very common to write numerical algorithms that are formulated algorithmically as while loops as for loops instead, i.e. instead of while check_termination(state) update!(state) end implement such algorithms instead as for iter=1:maxiter update!(state) check_termination(state) && break end In this case 'maxiter' serves as a circuit breaker to limit the total compute time of the calculation. In practice finding out the actual number of iterates computed is a useful diagnostic for convergence and is sometimes necessary to return the correct result from a calculation. In such situations I find myself writing this pattern frequently: numiters = 0 for iter=1:maxiter numiters = iter update!(state) check_termination(state) && break end just so that I can capture the final iteration count. Of course one can always bundle the iteration count into the state object, but sometimes one doesn't want to have to bother with constructing state objects. Thanks, Jiahao Chen Staff Research Scientist MIT Computer Science and Artificial Intelligence Laboratory
