17
votes
Accepted
Best practice to "continue" from inside a nested loop?
Don't nest: convert to functions instead. And have those functions return true if they perform their action and the subsequent steps can be skipped; false otherwise. That way you completely avoid the ...
13
votes
Best practice to "continue" from inside a nested loop?
From a more bird view perspective, I would refactor the code so that it looks like this... (in pseudo code, it's too long ago I touched C++)
void filterStrings(sl)
{
/* Filter string list */
...
10
votes
Best practice to "continue" from inside a nested loop?
I really like how @dagnelies starts. Short and to the point. A good use of high level abstraction. I'm only tweaking it's signature and avoiding a needless negative.
void ParsingTools::filterStrings(...
4
votes
Best practice to "continue" from inside a nested loop?
Just use a lambda for the predicate, and then use the power of standard algorithms and short-circuiting. No need for any convoluted or exotic control-flow:
void ParsingTools::filterStrings (...
3
votes
Simple tic-tac-toe GUI in Common Lisp: Avoid using Continuation Passing Style?
I've written quite a bit of code like what you post and now that I'm older (wiser is debatable, I'm sure) I've realized that there was one key tension in designs like this.
On the one hand you have ...
1
vote
Best practice to "continue" from inside a nested loop?
Several answers suggest a major refactor of the code. This is probably not a bad way to go, but I wanted to provide an answer which is more in line with the question itself.
Rule #1: Profile before ...
1
vote
Best practice to "continue" from inside a nested loop?
I think @dganelies has the right idea as a starting point, but I think I'd consider going a step further: write a generic function that can carry out the same pattern for (almost) any container, ...
1
vote
Best practice to "continue" from inside a nested loop?
There is also the option to make the content of the outer loop (the one you want to continue) a lambda, and simply use return.
It's surprisingly easy if you know lambdas; you basically start your loop ...
1
vote
Are first-class continuations useful in modern object-oriented programming languages?
The article referenced in the accepted answer is mostly true about the fact of the difficulties on reading/reasoning the CPS'd code by humans, but it is not quite convincing as the answer to this ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
continuation × 11tail-call × 3
scheme × 2
c++ × 1
javascript × 1
programming-practices × 1
programming-languages × 1
coding-style × 1
functional-programming × 1
language-agnostic × 1
clean-code × 1
language-design × 1
functions × 1
gui × 1
async × 1
recursion × 1
loops × 1
virtual-machine × 1
f# × 1
semantics × 1
common-lisp × 1
promises × 1
goto × 1
stack-oriented × 1