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 ║
║ The (below) two REXX statements aren't really necessary, but it shows how to
shows how to define any and all entries in a associative array so ║
║ define any and all entries in a associative array so that if a "key" is used that
isn't defined, it can be displayed to indicate such, or its value can be checked ║
║ that if a "key" is used that isn't defined, it can be displayed to ║
to determine if a particular associative array element has been set (defined). ║
indicate such, or its value can be checked to determine if a
╚════════════════════════════════════════════════════════════════════════════════════╝*/
particular associative array element has been set (defined).
stateF.= ' [not defined yet] ' /*sets any/all state former capitols.*/
╚════════════════════════════════════════════════════════════════════╝*/
stateN.= ' [not defined yet] ' /*sets any/all state names. */

stateL=
stateF.=' [not defined yet] ' /*sets any/all state former capitols.*/
/*╔════════════════════════════════════════════════════════════════════════════════════╗
stateN.=' [not defined yet] ' /*sets any/all state names. */
║ The list of states (empty now). It's convenient to have them in alphabetic order;

they'll be listed in this order. In REXX, when a key is used, it's normally ║
stateL= /*╔════════════════════════════════════════════════════════════════════╗
stored (internally) as as uppercase characters (as in the examples below).
║ The list of states (empty now). It's convenient to have them in ║
Actually, any characters can be used, including blank(s) and non─displayable ║
║ alphabetic order; they'll be listed in this order. With a little ║
║ more code, they could be sorted quite easily.
characters (including '00'x, 'ff'x, commas, periods, quotes, ···). ║
╚════════════════════════════════════════════════════════════════════════════════════╝*/
║ ║
In REXX, when a "key" is used, it's normally stored (internally)
as uppercase characters (as in the examples below). Actually, any
characters can be used, including blank(s) and non─displayable ║
║ 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 (joint)'
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: arg code; parse arg ,name,cap /*get uppercase code; get name &capitol*/
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.*/</lang>
return /*return to invoker, SETSC is finished.*/
</lang>
'''output'''
'''output'''
<pre>
<pre>
the former capital of (AL) Alabama was Tuscaloosa
the former capitol of (AL) Alabama was Tuscaloosa
the former capital of (CA) California was Benicia
the former capitol of (CA) California was Benicia
the former capital of (CO) Colorado was Denver City
the former capitol of (CO) Colorado was Denver City
the former capital of (CT) Connecticut was Hartford and New Haven (joint)
the former capitol of (CT) Connecticut was Hartford and New Haven (jointly)
the former capital of (DE) Delaware was New-Castle
the former capitol of (DE) Delaware was New-Castle
the former capital of (GA) Georgia was Milledgeville
the former capitol of (GA) Georgia was Milledgeville
the former capital of (IL) Illinois was Vandalia
the former capitol of (IL) Illinois was Vandalia
the former capital of (IN) Indiana was Corydon
the former capitol of (IN) Indiana was Corydon
the former capital of (IA) Iowa was Iowa City
the former capitol of (IA) Iowa was Iowa City
the former capital of (LA) Louisiana was New Orleans
the former capitol of (LA) Louisiana was New Orleans
the former capital of (ME) Maine was Portland
the former capitol of (ME) Maine was Portland
the former capital of (MI) Michigan was Detroit
the former capitol of (MI) Michigan was Detroit
the former capital of (MS) Mississippi was Natchez
the former capitol of (MS) Mississippi was Natchez
the former capital of (MO) Missouri was Saint Charles
the former capitol of (MO) Missouri was Saint Charles
the former capital of (MT) Montana was Virginia City
the former capitol of (MT) Montana was Virginia City
the former capital of (NE) Nebraska was Lancaster
the former capitol of (NE) Nebraska was Lancaster
the former capital of (NH) New Hampshire was Exeter
the former capitol of (NH) New Hampshire was Exeter
the former capital of (NY) New York was New York
the former capitol of (NY) New York was New York
the former capital of (NC) North Carolina was Fayetteville
the former capitol of (NC) North Carolina was Fayetteville
the former capital of (OH) Ohio was Chillicothe
the former capitol of (OH) Ohio was Chillicothe
the former capital of (OK) Oklahoma was Guthrie
the former capitol of (OK) Oklahoma was Guthrie
the former capital of (PA) Pennsylvania was Lancaster
the former capitol of (PA) Pennsylvania was Lancaster
the former capital of (SC) South Carolina was Charlestown
the former capitol of (SC) South Carolina was Charlestown
the former capital of (TN) Tennessee was Murfreesboro
the former capitol of (TN) Tennessee was Murfreesboro
the former capital of (VT) Vermont was Windsor
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. &nbsp; Unfortunately, there's a duplicate &nbsp; (Lancaster).
When this example was started, the intention was to list the former capitals by key. &nbsp; Unfortunately, there's a duplicate &nbsp; (Lancaster).