Anonymous user
Associative array/Iteration: Difference between revisions
m
→{{header|REXX}}: changed/added comments and whitespace, changed indentations, corrected a misspelling and a typo.
(→{{header|Ruby}}: renamed myDict to my_dict) |
m (→{{header|REXX}}: changed/added comments and whitespace, changed indentations, corrected a misspelling and a typo.) |
||
Line 2,213:
=={{header|REXX}}==
<lang rexx>/*REXX program
/*╔════════════════════════════════════════════════════════════════════╗
╚════════════════════════════════════════════════════════════════════╝*/
stateF.=' [not defined yet] ' /*sets any/all state former caps.*/▼
stateN.=' [not defined yet] ' /*sets any/all state names. */▼
│ In REXX, when a "key" is used, it's normally stored (internally) │▼
│ as uppercase characters (as in the examples below). Actually, any │▼
/*betic order; they'll be listed in this order. With a */▼
call setSC 'al', "Alabama" ,'Tuscaloosa'▼
▲stateN.=' [not defined yet] ' /*sets any/all state names. */
call setSC 'ca', "California" ,'Benicia'▼
call setSC 'co', "Colorado" ,'Denver City'▼
call setSC 'ct', "Connecticut" ,'Hartford and New Haven (joint)'▼
call setSC 'de', "Delaware" ,'New-Castle'▼
call setSC 'ga', "Georgia" ,'Milledgeville'▼
call setSC 'il', "Illinois" ,'Vandalia'▼
call setSC 'in', "Indiana" ,'Corydon'▼
call setSC 'ia', "Iowa" ,'Iowa City'▼
call setSC 'la', "Louisiana" ,'New Orleans'▼
call setSC 'me', "Maine" ,'Portland'▼
call setSC 'mi', "Michigan" ,'Detroit'▼
call setSC 'ms', "Mississippi" ,'Natchez'▼
call setSC 'mo', "Missoura" ,'Saint Charles'▼
call setSC 'mt', "Montana" ,'Virginia City'▼
call setSC 'ne', "Nebraska" ,'Lancaster'▼
call setSC 'nh', "New Hampshire" ,'Exeter'▼
call setSC 'ny', "New York" ,'New York'▼
call setSC 'nc', "North Carolina" ,'Fayetteville'▼
call setSC 'oh', "Ohio" ,'Chillicothe'▼
call setSC 'ok', "Oklahoma" ,'Guthrie'▼
call setSC 'pa', "Pennsylvania" ,'Lancaster'▼
call setSC 'sc', "South Carolina" ,'Charlestown'▼
call setSC 'tn', "Tennessee" ,'Murfreesboro'▼
call setSC 'vt', "Vermont" ,'Windsor'▼
stateL= /*╔════════════════════════════════════════════════════════════════════╗
do j=1 for words(stateL) /*show all capitals that were set*/▼
say 'the former capital of ('q") " stateN.q " was " stateC.q▼
setSC: arg code; parse arg ,name,cap /*get upper code, get name & cap.*/▼
╚════════════════════════════════════════════════════════════════════╝*/
stateC.code=cap /*set the state's capital. */▼
return /*return to invoker, SET is done.*/</lang>▼
▲call setSC 'al', "Alabama" , 'Tuscaloosa'
▲call setSC 'ca', "California" , 'Benicia'
▲call setSC 'co', "Colorado" , 'Denver City'
▲call setSC 'ct', "Connecticut" , 'Hartford and New Haven (joint)'
▲call setSC 'de', "Delaware" , 'New-Castle'
▲call setSC 'ga', "Georgia" , 'Milledgeville'
▲call setSC 'il', "Illinois" , 'Vandalia'
▲call setSC 'in', "Indiana" , 'Corydon'
▲call setSC 'ia', "Iowa" , 'Iowa City'
▲call setSC 'la', "Louisiana" , 'New Orleans'
▲call setSC 'me', "Maine" , 'Portland'
▲call setSC 'mi', "Michigan" , 'Detroit'
▲call setSC 'ms', "Mississippi" , 'Natchez'
▲call setSC 'mt', "Montana" , 'Virginia City'
▲call setSC 'ne', "Nebraska" , 'Lancaster'
▲call setSC 'nh', "New Hampshire" , 'Exeter'
▲call setSC 'ny', "New York" , 'New York'
▲call setSC 'nc', "North Carolina" , 'Fayetteville'
▲call setSC 'oh', "Ohio" , 'Chillicothe'
▲call setSC 'ok', "Oklahoma" , 'Guthrie'
▲call setSC 'pa', "Pennsylvania" , 'Lancaster'
▲call setSC 'sc', "South Carolina" , 'Charlestown'
▲call setSC 'tn', "Tennessee" , 'Murfreesboro'
▲call setSC 'vt', "Vermont" , 'Windsor'
q=word(stateL, j) /*get the next (USA) state in the list.*/
end /*j*/ /* [↑] show states that were defined.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
stateL=stateL code /*keep a list of all the US state codes*/
stateC.code=cap /* " " " " capitol. */
'''output'''
<pre>
the former capital of (AL) Alabama was Tuscaloosa
|