in reply to Re: Variable in a foreach loop
in thread Variable in a foreach loop
Hi perldigious,
... and then print the value of $max_rows one additional time.
ravi45722 is correct that the final print prints "0" - see my reply as to why.
use strict; use warnings; my $max_cols = 2; my $max_rows = 3; my $row_element = 0; foreach my $col_element (0 .. $max_cols) { foreach $row_element (0 .. $max_rows) { print "$row_element\n"; } } print "Last: $row_element\n"; __END__ 0 1 2 3 0 1 2 3 0 1 2 3 Last: 0
Regards,
-- Hauke D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Variable in a foreach loop
by perldigious (Priest) on Jul 14, 2016 at 13:51 UTC |