RosettaCodeData/Task/Associative-array-Iteration/REXX/associative-array-iteration.rexx

66 lines
1.9 KiB
Rexx
Raw Permalink Normal View History

2026-04-30 12:34:36 -04:00
-- 21 Feb 2026
2026-02-01 16:33:20 -08:00
include Setting
2023-07-01 11:58:00 -04:00
2025-08-11 18:05:26 -07:00
say 'ASSOCIATIVE ARRAY: ITERATION'
say version
say
list=''; arra.=''; w=0
-- States with former capitals: key, name, capital
call SetStateCap 'al','Alabama','Tuscaloosa'
call SetStateCap 'ca','California','Benicia'
call SetStateCap 'co','Colorado','Denver City'
call SetStateCap 'ct','Connecticut','Hartford and New Haven'
call SetStateCap 'de','Delaware','New-Castle'
call SetStateCap 'ga','Georgia','Milledgeville'
call SetStateCap 'il','Illinois','Vandalia'
call SetStateCap 'in','Indiana','Corydon'
call SetStateCap 'ia','Iowa','Iowa City'
call SetStateCap 'la','Louisiana','New Orleans'
call SetStateCap 'me','Maine','Portland'
call SetStateCap 'mi','Michigan','Detroit'
call SetStateCap 'ms','Mississippi','Natchez'
call SetStateCap 'mo','Missouri','Saint Charles'
call SetStateCap 'mt','Montana','Virginia City'
call SetStateCap 'ne','Nebraska','Lancaster'
call SetStateCap 'nh','New Hampshire','Exeter'
call SetStateCap 'ny','New York','New York'
call SetStateCap 'nc','North Carolina','Fayetteville'
call SetStateCap 'oh','Ohio','Chillicothe'
call SetStateCap 'ok','Oklahoma','Guthrie'
call SetStateCap 'pa','Pennsylvania','Lancaster'
call SetStateCap 'sc','South Carolina','Charlestown'
call SetStateCap 'tn','Tennessee','Murfreesboro'
call SetStateCap 'vt','Vermont','Windsor'
arra.0=w
-- Loop through list
say 'Using a list...'
do w = 1 to words(list)
a=Word(list,w)
say 'The former capital of' stna.a '('a')' 'was' stca.a
end
say
2026-02-01 16:33:20 -08:00
-- Loop through array...'
2025-08-11 18:05:26 -07:00
say 'Using an array...'
do w = 1 to arra.0
a=arra.w
say 'The former capital of' stna.a '('a')' 'was' stca.a
end
say
-- Show all vars
2026-04-30 12:34:36 -04:00
call Showvars
2025-08-11 18:05:26 -07:00
exit
SetStateCap:
parse arg code,name,cap
code=Upper(code)
-- Next row in associative array
stna.code=name; stca.code=cap
-- Track keys in a list
list=list code
-- Track keys in an array
w=w+1; arra.w=code
return
2026-04-30 12:34:36 -04:00
-- Showvars
2026-02-01 16:33:20 -08:00
include Math