Jump to content

Associative array/Iteration: Difference between revisions

m
→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations.
m (added whitespace to the task's preamble.)
m (→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations.)
Line 2,221:
=={{header|REXX}}==
<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
shows how to 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 to determine if a
║ 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 stored (internally)
stateL= /*╔════════════════════════════════════════════════════════════════════╗
stored (internally) as as uppercase characters (as in the examples below). Actually, any
║ 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 ║
characters (including '00'x, 'ff'x, commas, periods, ║ more codequotes, they could be sorted quite easily···).
╚════════════════════════════════════════════════════════════════════════════════════╝*/
║ ║
║ 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 'ca', "California" , 'Benicia'
call setSC 'co', "Colorado" , 'Denver City'
call setSC 'ct', "Connecticut" , 'Hartford and New Haven (jointjointly)'
call setSC 'de', "Delaware" , 'New-Castle'
call setSC 'ga', "Georgia" , 'Milledgeville'
Line 2,275 ⟶ 2,269:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
setSC: arg code; parse arg code,name,cap; upper code /*get uppercase code; get, name &capitol cap.; uppercase code*/
stateL=stateL code /*keep a list of all the US state codes*/
stateN.code=name /*set (define) the state's name. */
stateC.code=cap /* " " " " capitol. */
return /*return to invoker, SETSC is finished.*/</lang>
</lang>
'''output'''
<pre>
the former capitalcapitol of (AL) Alabama was Tuscaloosa
the former capitalcapitol of (CA) California was Benicia
the former capitalcapitol of (CO) Colorado was Denver City
the former capitalcapitol of (CT) Connecticut was Hartford and New Haven (jointjointly)
the former capitalcapitol of (DE) Delaware was New-Castle
the former capitalcapitol of (GA) Georgia was Milledgeville
the former capitalcapitol of (IL) Illinois was Vandalia
the former capitalcapitol of (IN) Indiana was Corydon
the former capitalcapitol of (IA) Iowa was Iowa City
the former capitalcapitol of (LA) Louisiana was New Orleans
the former capitalcapitol of (ME) Maine was Portland
the former capitalcapitol of (MI) Michigan was Detroit
the former capitalcapitol of (MS) Mississippi was Natchez
the former capitalcapitol of (MO) Missouri was Saint Charles
the former capitalcapitol of (MT) Montana was Virginia City
the former capitalcapitol of (NE) Nebraska was Lancaster
the former capitalcapitol of (NH) New Hampshire was Exeter
the former capitalcapitol of (NY) New York was New York
the former capitalcapitol of (NC) North Carolina was Fayetteville
the former capitalcapitol of (OH) Ohio was Chillicothe
the former capitalcapitol of (OK) Oklahoma was Guthrie
the former capitalcapitol of (PA) Pennsylvania was Lancaster
the former capitalcapitol of (SC) South Carolina was Charlestown
the former capitalcapitol of (TN) Tennessee was Murfreesboro
the former capitalcapitol of (VT) Vermont was Windsor
</pre>
When this example was started, the intention was to list the former capitals by key. &nbsp; Unfortunately, there's a duplicate &nbsp; (Lancaster).
Cookies help us deliver our services. By using our services, you agree to our use of cookies.