in reply to Re^2: Printing a hollow square of Asterisks
in thread Printing a hollow square of Asterisks
The above snippet takes a number afterward to select the size. In the case of nothing given, $n gets a value of 0. The q{*} x $n will give nothing if $n is 0, or $n asterisks. The if statement prevents the loop for the sides and printing a bottom if $n is 1. The loop is triggered only if $n - 1 is greater than 2 (ie, 3 or more), and prints only the asteristks on either edge, producing the "hole" in the middle.
Hope that helps.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Printing a hollow square of Asterisks
by Rafter (Initiate) on Mar 04, 2009 at 15:42 UTC | |
by Anonymous Monk on Mar 04, 2009 at 15:45 UTC | |
by ww (Archbishop) on Mar 04, 2009 at 18:58 UTC |