Associative array/Iteration: Difference between revisions
Content added Content deleted
m (added whitespace to the task's preamble.) |
m (→{{header|REXX}}: changed/added comments and whitespace, changed indentations.) |
||
Line 2,221: | Line 2,221: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program demonstrates how to set and display values for an associative array. */ |
<lang rexx>/*REXX program demonstrates how to set and display values for an associative array. */ |
||
/*╔════════════════════════════════════════════════════════════════════════════════════╗ |
|||
/*╔════════════════════════════════════════════════════════════════════╗ |
|||
║ The (below) two REXX statements aren't really necessary, but it shows how to ║ |
|||
║ define any and all entries in a associative array so that if a "key" is used that ║ |
|||
⚫ | |||
║ that if a "key" is used that isn't defined, it can be displayed to ║ |
|||
⚫ | |||
⚫ | |||
╚════════════════════════════════════════════════════════════════════════════════════╝*/ |
|||
⚫ | |||
⚫ | |||
╚════════════════════════════════════════════════════════════════════╝*/ |
|||
⚫ | |||
stateL= |
|||
⚫ | |||
/*╔════════════════════════════════════════════════════════════════════════════════════╗ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
stateL= /*╔════════════════════════════════════════════════════════════════════╗ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
║ alphabetic order; they'll be listed in this order. With a little ║ |
|||
║ characters (including '00'x, 'ff'x, commas, periods, quotes, ···). ║ |
|||
╚════════════════════════════════════════════════════════════════════════════════════╝*/ |
|||
║ ║ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
║ characters (including '00'x, 'ff'x, commas, periods, quotes, ···).║ |
|||
╚════════════════════════════════════════════════════════════════════╝*/ |
|||
call setSC 'al', "Alabama" , 'Tuscaloosa' |
call setSC 'al', "Alabama" , 'Tuscaloosa' |
||
call setSC 'ca', "California" , 'Benicia' |
call setSC 'ca', "California" , 'Benicia' |
||
call setSC 'co', "Colorado" , 'Denver City' |
call setSC 'co', "Colorado" , 'Denver City' |
||
call setSC 'ct', "Connecticut" , 'Hartford and New Haven ( |
call setSC 'ct', "Connecticut" , 'Hartford and New Haven (jointly)' |
||
call setSC 'de', "Delaware" , 'New-Castle' |
call setSC 'de', "Delaware" , 'New-Castle' |
||
call setSC 'ga', "Georgia" , 'Milledgeville' |
call setSC 'ga', "Georgia" , 'Milledgeville' |
||
Line 2,275: | Line 2,269: | ||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
setSC: |
setSC: parse arg code,name,cap; upper code /*get code, name & cap.; uppercase code*/ |
||
stateL=stateL code /*keep a list of all the US state codes*/ |
stateL=stateL code /*keep a list of all the US state codes*/ |
||
stateN.code=name /*set (define) the state's name. */ |
stateN.code=name /*set (define) the state's name. */ |
||
stateC.code=cap /* " " " " capitol. */ |
stateC.code=cap /* " " " " capitol. */ |
||
return /*return to invoker, SETSC is finished.*/ |
return /*return to invoker, SETSC is finished.*/ |
||
</lang> |
|||
'''output''' |
'''output''' |
||
<pre> |
<pre> |
||
the former |
the former capitol of (AL) Alabama was Tuscaloosa |
||
the former |
the former capitol of (CA) California was Benicia |
||
the former |
the former capitol of (CO) Colorado was Denver City |
||
the former |
the former capitol of (CT) Connecticut was Hartford and New Haven (jointly) |
||
the former |
the former capitol of (DE) Delaware was New-Castle |
||
the former |
the former capitol of (GA) Georgia was Milledgeville |
||
the former |
the former capitol of (IL) Illinois was Vandalia |
||
the former |
the former capitol of (IN) Indiana was Corydon |
||
the former |
the former capitol of (IA) Iowa was Iowa City |
||
the former |
the former capitol of (LA) Louisiana was New Orleans |
||
the former |
the former capitol of (ME) Maine was Portland |
||
the former |
the former capitol of (MI) Michigan was Detroit |
||
the former |
the former capitol of (MS) Mississippi was Natchez |
||
the former |
the former capitol of (MO) Missouri was Saint Charles |
||
the former |
the former capitol of (MT) Montana was Virginia City |
||
the former |
the former capitol of (NE) Nebraska was Lancaster |
||
the former |
the former capitol of (NH) New Hampshire was Exeter |
||
the former |
the former capitol of (NY) New York was New York |
||
the former |
the former capitol of (NC) North Carolina was Fayetteville |
||
the former |
the former capitol of (OH) Ohio was Chillicothe |
||
the former |
the former capitol of (OK) Oklahoma was Guthrie |
||
the former |
the former capitol of (PA) Pennsylvania was Lancaster |
||
the former |
the former capitol of (SC) South Carolina was Charlestown |
||
the former |
the former capitol of (TN) Tennessee was Murfreesboro |
||
the former |
the former capitol of (VT) Vermont was Windsor |
||
</pre> |
</pre> |
||
When this example was started, the intention was to list the former capitals by key. Unfortunately, there's a duplicate (Lancaster). |
When this example was started, the intention was to list the former capitals by key. Unfortunately, there's a duplicate (Lancaster). |