http://www.perlmonks.org?node_id=1041511


in reply to Perl Loops

Hi stam1982

For:
#!/usr/bin/perl use strict; use warnings; for (my $n = 2; $n < 21; $n += 2){ print "$n\n"; }
while:
#!/usr/bin/perl use strict; use warnings; my @evens; my $n = 0; my $number_to_give_up_at = 21; # $#evens will contain value of index of last element in @evens array while ($n++ < $number_to_give_up_at and $#evens < 9){ push @evens, $n if $n % 2 == 0; } print join("\n", @evens);

All is well

Replies are listed 'Best First'.
Re^2: Perl Loops
by stamp1982 (Novice) on Jun 29, 2013 at 21:08 UTC
    Farang: How will you do that using the until/do-until loops?