Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: do until loops

by Anonymous Monk
on Sep 19, 2002 at 11:35 UTC ( #199143=note: print w/ replies, xml ) Need Help??


in reply to Re: do until loops
in thread do until loops

Count iterations of failure, at a set count, exit..


Comment on Re: Re: do until loops
Re^3: do until loops
by Anonymous Monk on Feb 17, 2014 at 12:24 UTC
    How to exit ?? alst is not working

      From last:

      last cannot be used to exit a block that returns a value such as eval {}, sub {}, or do {}, and should not be used to exit a grep() or map() operation.

      Note that a block by itself is semantically identical to a loop that executes once. Thus last can be used to effect an early exit out of such a block.

      So, last doesn’t work in a do { ... } until (...); loop. But — put the whole construct inside a block, and last now works fine:

      #! perl use strict; use warnings; my $n = 42; { do { printf "n = %d\n", $n--; last if $n == 37; } until ($n <= 0); } print "Past the loop\n";

      Output:

      0:22 >perl 878_Tutorial.pl n = 42 n = 41 n = 40 n = 39 n = 38 Past the loop 0:22 >

      Hope that helps,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://199143]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2015-07-06 01:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls