Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: do until loops

by Anonymous Monk
on Aug 20, 2002 at 15:23 UTC ( #191478=note: print w/ replies, xml ) Need Help??

in reply to do until loops

Is it possible to stop the loop if the "until" condition is never met? I am coding some user system and I use a do { for { }} until { } loop until the user name input matches one from the database. Thanks for any help.

Comment on Re: do until loops
Re: do until loops
by Abigail-II (Bishop) on Aug 20, 2002 at 15:40 UTC
    Frankly, your question doesn't make sense. The entire point of a do {} until loop is to repeat the loop until the condition is met. When would you stop anyway? How will you know the condition will never be met? (In general, you cannot not - that's what the halting problem is about).


Re: Re: do until loops
by Anonymous Monk on Sep 19, 2002 at 11:35 UTC
    Count iterations of failure, at a set count, exit..
      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";


        0:22 >perl 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,

Re: Re: do until loops
by Anonymous Monk on Sep 09, 2003 at 23:09 UTC
    You can have a certain number of tries based on the number of values in the database: $dbnumber=66; #This would be the number of usernames. $value=1; do{ #Your input line would go here, obviously not print value. $value=$value+1; } until($value==$dbnum); #This makes it stop after checking the last value in the database.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2014-10-23 15:24 GMT
Find Nodes?
    Voting Booth?

    For retirement, I am banking on:

    Results (125 votes), past polls