Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^5: SIMPLE way to write these?

by GotToBTru (Prior)
on Feb 04, 2014 at 15:04 UTC ( [id://1073411]=note: print w/replies, xml ) Need Help??


in reply to Re^4: SIMPLE way to write these?
in thread SIMPLE way to write these?

You are comparing $number2 and $number1 in your while; neither ever changes. That's why you get an infinite loop. Here is a solution that preserves the value in $number1.

my $number1 = 1; my $number2 = 10; my $i = $number1; while ($number2 >= $i) { print $i++,"\n"; }

Replies are listed 'Best First'.
Re^6: SIMPLE way to write these?
by Jenda (Abbot) on Feb 05, 2014 at 09:59 UTC

    I think most would write this using the three argument for() statement:

    my $number1 = 1; my $number2 = 10; for (my $i = $number1; $i <= $number2; $i++) { print "$i\n"; }

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found