While it can be done with a single loop, it seems to me you have to use less intuitive coding techniques to enforce that arbitrary constraint.
I'm beyond understanding why not just use a nested loop and be done with it.
#!/usr/bin/perl -w
use strict;
foreach my $y_axis (1..8) {
my $output_text = '';
foreach my $x_axis (1..8) {
$output_text .= " $x_axis$y_axis ";
}
print "$output_text\n";
}
exit;
__END__
C:\Steve\Dev\PerlMonks\P-2013-10-03@1652-8x8-Loop>8x8.pl
11 21 31 41 51 61 71 81
12 22 32 42 52 62 72 82
13 23 33 43 53 63 73 83
14 24 34 44 54 64 74 84
15 25 35 45 55 65 75 85
16 26 36 46 56 66 76 86
17 27 37 47 57 67 77 87
18 28 38 48 58 68 78 88
That said, BrowserUK produced, as usual, a brilliant one-loop solution.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.