Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: while loops

by Glyndwr (Initiate)
on Jan 11, 2002 at 18:35 UTC ( #138008=note: print w/ replies, xml ) Need Help??


in reply to while loops

Yours

$num=20; $while($num<30){ print "num is $num\n"; $num=$num+1;\n ; }
should be

$num=20;<BR> while($num<30){ print "num is $num\n"; $num+=$num;\n; }


Comment on Re: while loops
Select or Download Code
Re: Re: while loops
by rob_au (Abbot) on Jan 11, 2002 at 18:41 UTC
    No, not at all - Your code will only pass through a single iteration of the loop as on the first pass, the value of $num is added to $num. The result is that $num equals 40 and the while loop is exited. I think you may have been meaning, ignoring formatting syntax errors ...

    $num = 20; while ($num < 30) { print "num is $num\n"; ++$num; }

    Although, good pick up on the syntax error with the line - $while($num<30){ - Although this had been addressed previously within this thread.

     

    perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

      yes , thanks

      in this case would $num++ also work

Re^2: while loops
by lvanhout (Curate) on Jun 15, 2004 at 17:42 UTC
    Still not there.

    $num=20; while($num<30) { print "num is $num\n"; <b><u>$num+=$num;\n</b></u> } #I think you ment: $num += 1; #Though these should work also: $num++; ++$num;
    There is also an extra "\n;" in the code in the reply.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-09-20 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls