I am looking for a way to jump to the last iteration of a loop with a dynamic termination condition.
Consider the following model
LoopManager loopManager(/* params */)
for (; loopManager.MustKeepIterating() && loopManager.foo() /* && ... */; loopManager.Increment())
{
/* ... */
loopManager.Update();
}
In this scenario, I can't just loop until n-1
where n
is the termination valued condition, because the termination condition is dynamic by depending on the body of the function.
What would be interesting or elegant ways to jump the last iteration in this loop before it gets terminated, as to investigate the functions in the body, at that last iteration? I need to investigate the last iteration, but there are thousands of iterations in my case.
CodePudding user response:
Your model needs to be modified to hit the break point:
LoopManager loopManager(/* params */);
auto var =loopManager.MustKeepIterating() && loopManager.foo() ;
for (; var; loopManager.Increment())// add conitional break point this line. Expression e.g.: var== false
{
/* ... */
loopManager.Update();
var=loopManager.MustKeepIterating() && loopManager.foo() /* && ... */
}