in reply to (jcwren) RE: (tye)Re: The last command is like the break statement in C
in thread The last command is like the break statement in C

Thanks. I forgot about "continue" in C, which I don't recall ever using. But this strengthens the story...

Now that Perl has "redo" and "next", both of these "continue" the loop processing so they really both had to be named something other than "continue". Plus, Perl lets you write for(a;b;c) as a;while(b){}continue{c} (I hope I got that right). It makes sense to use "continue" here since that block is what is executed whenever you decide to continue looping. So having "continue" introduce that block as well as be a loop flow modifier would probably lead to more parsing confusion. So we had to rename "continue", we might as well rename "break" as well.

I also wondered if "break" was being saved for when Perl adds a real "case" statement. I hate this in C:

while( bool ) { switch( input ) { case END: break; } }
What I really want to do is break out of the while loop. The work-arounds for this overloading of "break" in C are usually a bit ugly (depending on the specifics). So if Perl uses "break" for "case" statements, then I could code "last" above and get what I often want very easily.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
RE (tilly) 3: The last command is like the break statement in C
by tilly (Archbishop) on Sep 27, 2000 at 19:43 UTC
    Just to confuse C programmers, Perl has a continue keyword that is used in looping. If after your main loop block you have a block labelled continue, it will be executed between iterations. For giggles and grins, within a continue block the word next will restart the continue block. Combining continue, redo, and next properly you can write a triple-loop in one loop. I have no idea why someone would want to do this, but you can.