RosettaCodeData/Task/Loops-Nested/REXX/loops-nested.rexx

23 lines
1.5 KiB
Rexx
Raw Permalink Normal View History

2016-12-05 22:15:40 +01:00
/*REXX program loops through a two-dimensional array to search for a '20' (twenty). */
parse arg rows cols targ . /*obtain optional arguments from the CL*/
if rows=='' | rows=="," then rows=60 /*Rows not specified? Then use default*/
if cols=='' | cols=="," then cols=10 /*Cols " " " " " */
if targ=='' | targ=="," then targ=20 /*Targ " " " " " */
w=max(length(rows), length(cols), length(targ)) /*W: used for formatting the output. */
not= 'not' /* [↓] construct the 2─dimension array*/
do row=1 for rows /*ROW is the 1st dimension of array. */
do col=1 for cols /*COL " " 2nd " " " */
@.row.col=random(1, targ) /*create some positive random integers.*/
2013-04-10 21:29:02 -07:00
end /*row*/
end /*col*/
2016-12-05 22:15:40 +01:00
do r=1 for rows /* ◄───────────────── now, search for the target {20}.*/
2015-02-20 00:35:01 -05:00
do c=1 for cols
2016-12-05 22:15:40 +01:00
say left('@.'r"."c, 3+w+w) '=' right(@.r.c, w) /*show an array element.*/
if @.r.c==targ then do; not=; leave r; end /*found the targ number?*/
2015-02-20 00:35:01 -05:00
end /*c*/
end /*r*/
2013-04-10 21:29:02 -07:00
2016-12-05 22:15:40 +01:00
say right( space( 'Target' not "found:" ) targ, 33, '')
/*stick a fork in it, we're all done. */