I use for(;;){...} rather while(1){...} (less lying), but I like this redo idea. I didn't know it could be used on bare blocks before this thread. However, I'm concerned about the lack of visual junk at the top that people expect for loops. Do you think there's any penalty or side-effects to using do { ... } instead of { ... }?
| [reply] [d/l] [select] |
Do you think there's any penalty or side-effects to using do { ... } instead of { ... }?
Other than it won't work? That's a pretty severe penalty. last/next/redo do not pay attention to do-blocks.
| [reply] |
There isn't necessarily any reason not to use do { ... }, as long as you realize that a do block isn't 100% like bare blocks. I look at do blocks kind of like immediately executing subroutines minus the parameter list, since do blocks have return values vaguely similar to subs.
If you're concerned about the visual ambiguity of a bare block with a redo inside it, you can always start it off with a label, as in:
LOOP: {
# do some stuff
redo;
}
However, even though while(1) (and even for(;;)) sort of perpetrates a fib, it is still more flexible to use such constructs over the bare block / redo method, because bare blocks don't support continue, occasionally useful with explicit loops.
| [reply] [d/l] [select] |