Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: do while loops

by Anonymous Monk
on Oct 24, 2004 at 03:41 UTC ( #401962=note: print w/ replies, xml ) Need Help??


in reply to do while loops

ok.. the code is bad. That situations cause problems to novices

$value=5 <------ ok that is the problem it does not have ; do{ print "$value\n"; $value=$value-1; } while($value>10);

ok the correct code is

$value=5; # now have ; do{ print "$value\n"; $value=$value-1; } while($value>10);

have a fun

20041024 Edit by ysth: change p tags to code


Comment on Re: do while loops
Select or Download Code
Re^2: do while loops
by Anonymous Monk on Jan 20, 2006 at 22:10 UTC
    Actually, I think the problem is larger than that.
    shouldn't it be:
    $value = 15; # 15, not 5. 5 doesn't make sense if we're not increment +ing. do { print "$value\n"; $value = $value - 1; } while($value > 10);

    jdporter fixed formatting

      The point was that the test happens at the end, so the loop executes once even if the value starts out < 10.

      Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (17)
As of 2014-07-29 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (225 votes), past polls