in reply to SIMPLE way to write these?

for also introduces a loop. The canonical way to print the numbers between 1 and 10 would be
for my $i (1 .. 10) { print "$i\n"; }

Or, even, something like

use feature qw{ say }; say for 1 .. 10;

With a while loop, you just have to initialize a counter, and then check its value against the final value in the loop condition:

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

The factorial is left as an exercise for the reader.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: SIMPLE way to write these?
by Anonymous Monk on Feb 04, 2014 at 14:13 UTC
    Aham, I see, but how can you use a while loop to print all numbers between $number1 and $number2 ( I mean if they are both user-defined)?
      Ahem, just replace 1 (that is not followed by 0) with $number1; and similarly, replace 10 with $number2.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Like this?
        my $i = $number1; while ($number2 >= $number1) { print $i++, "\n"; }
        It goes into an infinite loop...I am clearly making a silly mistake here...