Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl loops should use break, not last

Reply
Thread Tools

Perl loops should use break, not last

 
 
Jeremy Morton
Guest
Posts: n/a
 
      01-31-2005
"Abigail" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Jeremy Morton ((E-Mail Removed)) wrote on MMMMCLXX September MCMXCIII in
> <URL:news:41fd39a4$0$26027$(E-Mail Removed) >:
> %%
> %% > One of the reasons 'last' isn't called 'break' is that 'last' isn't
> %% > the same as 'break'. 'break' breaks the current loop - while 'last'
> %% > takes an optional argument, indicating the top level loop that will
> %% > be exited.
> %%
> %% Hang on, are you saying 'break' has a meaning in Perl?
>
> No, I did not.
>


The what did you mean when you said 'last' isn't the same as break? AFAICT,
Perl's 'last' is identical to C and other languages's 'break', assuming that
break can take an optional argument specifying which level of block to break
out of (which often, it can).


--
Best regards,
Jeremy Morton (Jez)


 
Reply With Quote
 
 
 
 
Big and Blue
Guest
Posts: n/a
 
      01-31-2005
Jeremy Morton wrote:
>
> The what did you mean when you said 'last' isn't the same as break? AFAICT,
> Perl's 'last' is identical to C and other languages's 'break' assuming that
> break can take an optional argument specifying which level of block to break
> out of (which often, it can).


But it can't in C, so it's not identical to that.

FWIW: (straining my memory here) Prime has a system language (SPL) that
was PL/1 based, and it had a last statement which *was identical* to Perl's
(ie: it allowed you to say for which block this was the last statement).



--
Just because I've written it doesn't mean that
either you or I have to believe it.
 
Reply With Quote
 
 
 
 
Big and Blue
Guest
Posts: n/a
 
      01-31-2005
Big and Blue wrote:
>
> FWIW: (straining my memory here) Prime has a system language (SPL) that
> was PL/1 based, and it had a last statement which *was identical* to
> Perl's (ie: it allowed you to say for which block this was the last
> statement).


Retracting this (a brain cell has come back to life). It actually had
a "leave" statement rather than a "last". What it didn't have, though, was
a "break".

--
Just because I've written it doesn't mean that
either you or I have to believe it.
 
Reply With Quote
 
Arndt Jonasson
Guest
Posts: n/a
 
      01-31-2005

"Alan J. Flavell" <(E-Mail Removed)> writes:
> On Sat, 29 Jan 2005, A. Sinan Unur wrote:
>
> > "Jeremy Morton" <(E-Mail Removed)> wrote in
> > > semantically more accurate to say 'break' -

> >
> > I have a sneaking suspicion that you are trolling,

>
> I think you're being rather uncharitable. As far as I recall, "break"
> /was/ the term used in BCPL for effectively the same purpose:
>
> | causes execution to be resumed at the point just after
> | the smallest textually enclosing loop command
>
> it says in the old manual.
>
> But the Perl usage is now well established, and the other arguments
> on this thread are well taken. I doubt there's anything to be gained
> by trying to change the Perl usage now, and I don't see any net
> benefit in it.


The absence of "break" in Perl is pointed out in "perltrap.pod". What is
not pointed out explicitly there is that if you mistakenly write "break"
when you should have written "last", and also do not use "use warnings;",
no hint of anything wrong will be given when the code is executed - the
"break" will be a no-op. It took me a little while to find this error
someone else had made in one of the first Perl scripts I had to debug.
(I didn't know about "use warnings;" at the time.)
 
Reply With Quote
 
Charlton Wilbur
Guest
Posts: n/a
 
      01-31-2005
>>>>> "JM" == Jeremy Morton <(E-Mail Removed)> writes:

JM> Why does every genuine question to a Usenet group have to be a
JM> troll? See this is why I don't often post on bloody Usenet.

Asking and getting an answer is one thing. Continuing to argue after
you get a clear answer is what makes you seem like a troll.

Perl uses "last" and "next", not "break" and "continue." Perl is not
C; if you want C, go use C. If you don't want C, but think Perl
should use these particular C keywords, you can write a source code
filter to change it. Have fun.

Charlton


--
cwilbur at chromatico dot net
cwilbur at mac dot com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
while-loops enter the last time after condition is filled? skanemupp@yahoo.se Python 4 04-07-2008 12:08 PM
skip last line in loops eight02645999@yahoo.com Python 15 12-18-2006 08:42 PM
Loops with loops using html-template Me Perl Misc 2 01-12-2006 05:07 PM
Perl loops should use break, not last Jeremy Morton Perl 1 01-30-2005 10:50 PM
MS Perl question -- how to use hacked script to work correctly(was Question on loops and return values or sumpin) James Perl Misc 12 12-20-2004 04:15 PM



Advertisments