Brian Candler <b.candler / pobox.com> wrote/schrieb <c0239d01841781968588d12347943748 / ruby-forum.com>:

> Well, I don't really understand what's going on, but I observe from the 
> catch/throw version that the generated symbol is in a local variable and 
> doesn't appear to be passed downwards. So what's wrong with using the 
> same symbol everywhere?

I've looked for the simpliest example to demonstrate the diffence.

Run the program and let read it from standard input one line
consisting of an opening and a closing parenthesis, nothing else:
()

The output will be an empty line. (Well, not very exiting, but I've
looked for the simpliest example.)

BUT when using the same symbol everywhere rather than generated
symbols, then the program never returns: it hangs! Why?

> Or indeed, what's wrong with using loop { .... next ... } ?

Just replacing ``throw'' by ``next'' doesn't help in these situations:
loop { ... multiline { ... next ... } ... }
loop { ... character { ... next ... } ... }
                                      ^^^
                                      executed despite ``next''!

``next'' will then quit only the innermost block, that's not enough.
The code between the two closing curly braces will be executed, but it
shouldn't.

Regards
  Thomas