in reply to Useful uses of redo?

Frankly, I feel that while(1){...} is the lie, compared to { ....; redo; }. And nobody will argue that there isn't usefulness in neverending loops (even if those loops end with a last in there somewhere).


Dave

Replies are listed 'Best First'.
Re^2: Useful uses of redo?
by ikegami (Patriarch) on Aug 26, 2004 at 19:35 UTC

    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 { ... }?

      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.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a 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.


      Dave