Associative array/Iteration: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations.)
m (→‎{{header|REXX}}: aligned to capitols (in the output) for easier reading.)
Line 2,229: Line 2,229:
stateF.= ' [not defined yet] ' /*sets any/all state former capitols.*/
stateF.= ' [not defined yet] ' /*sets any/all state former capitols.*/
stateN.= ' [not defined yet] ' /*sets any/all state names. */
stateN.= ' [not defined yet] ' /*sets any/all state names. */
w = 0 /*the maximum length of a state name.*/
stateL=
stateL=
/*╔════════════════════════════════════════════════════════════════════════════════════╗
/*╔════════════════════════════════════════════════════════════════════════════════════╗
Line 2,265: Line 2,266:
do j=1 for words(stateL) /*show all capitols that were defined. */
do j=1 for words(stateL) /*show all capitols that were defined. */
q=word(stateL, j) /*get the next (USA) state in the list.*/
q=word(stateL, j) /*get the next (USA) state in the list.*/
say 'the former capitol of ('q") " stateN.q " was " stateC.q
say 'the former capitol of ('q") " left(stateN.q, w) " was " stateC.q
end /*j*/ /* [↑] show states that were defined.*/
end /*j*/ /* [↑] show states that were defined.*/
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
Line 2,271: Line 2,272:
setSC: parse arg code,name,cap; upper code /*get code, name & cap.; uppercase code*/
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; w=max(w,length(name)) /*define the state's name; max width. */
stateC.code=cap /* " " " " capitol. */
stateC.code=cap /* " " " code to the capitol*/
return /*return to invoker, SETSC is finished.*/
return /*return to invoker, SETSC is finished.*/</lang>
</lang>
'''output'''
'''output'''
<pre>
<pre>
the former capitol of (AL) Alabama was Tuscaloosa
the former capitol of (AL) Alabama was Tuscaloosa
the former capitol of (CA) California was Benicia
the former capitol of (CA) California was Benicia
the former capitol of (CO) Colorado was Denver City
the former capitol of (CO) Colorado was Denver City
the former capitol of (CT) Connecticut was Hartford and New Haven (jointly)
the former capitol of (CT) Connecticut was Hartford and New Haven (jointly)
the former capitol of (DE) Delaware was New-Castle
the former capitol of (DE) Delaware was New-Castle
the former capitol of (GA) Georgia was Milledgeville
the former capitol of (GA) Georgia was Milledgeville
the former capitol of (IL) Illinois was Vandalia
the former capitol of (IL) Illinois was Vandalia
the former capitol of (IN) Indiana was Corydon
the former capitol of (IN) Indiana was Corydon
the former capitol of (IA) Iowa was Iowa City
the former capitol of (IA) Iowa was Iowa City
the former capitol of (LA) Louisiana was New Orleans
the former capitol of (LA) Louisiana was New Orleans
the former capitol of (ME) Maine was Portland
the former capitol of (ME) Maine was Portland
the former capitol of (MI) Michigan was Detroit
the former capitol of (MI) Michigan was Detroit
the former capitol of (MS) Mississippi was Natchez
the former capitol of (MS) Mississippi was Natchez
the former capitol of (MO) Missouri was Saint Charles
the former capitol of (MO) Missouri was Saint Charles
the former capitol of (MT) Montana was Virginia City
the former capitol of (MT) Montana was Virginia City
the former capitol of (NE) Nebraska was Lancaster
the former capitol of (NE) Nebraska was Lancaster
the former capitol of (NH) New Hampshire was Exeter
the former capitol of (NH) New Hampshire was Exeter
the former capitol of (NY) New York was New York
the former capitol of (NY) New York was New York
the former capitol of (NC) North Carolina was Fayetteville
the former capitol of (NC) North Carolina was Fayetteville
the former capitol of (OH) Ohio was Chillicothe
the former capitol of (OH) Ohio was Chillicothe
the former capitol of (OK) Oklahoma was Guthrie
the former capitol of (OK) Oklahoma was Guthrie
the former capitol of (PA) Pennsylvania was Lancaster
the former capitol of (PA) Pennsylvania was Lancaster
the former capitol of (SC) South Carolina was Charlestown
the former capitol of (SC) South Carolina was Charlestown
the former capitol of (TN) Tennessee was Murfreesboro
the former capitol of (TN) Tennessee was Murfreesboro
the former capitol 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).