Associative array/Iteration: Difference between revisions
Content added Content deleted
(→{{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: | Line 2,213: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program |
<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 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 ║ |
|||
║ particular associative array element has been set (defined). ║ |
|||
╚════════════════════════════════════════════════════════════════════╝*/ |
|||
└────────────────────────────────────────────────────────────────────┘*/ |
|||
⚫ | |||
⚫ | |||
/*┌────────────────────────────────────────────────────────────────────┐ |
|||
⚫ | |||
⚫ | |||
│ characters can be used, including blank(s) and non-displayable │ |
|||
│ characters (including '00'x, 'ff'x, commas, periods, quotes, ···).│ |
|||
└────────────────────────────────────────────────────────────────────┘*/ |
|||
stateL='' /*list of states (empty now). It's nice to be in alpha-*/ |
|||
⚫ | |||
/*little more code, they could be sorted quite easily. */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
stateL= /*╔════════════════════════════════════════════════════════════════════╗ |
|||
⚫ | |||
║ The list of states (empty now). It's convenient to have them in ║ |
|||
⚫ | |||
⚫ | |||
║ more code, they could be sorted quite easily. ║ |
|||
║ ║ |
|||
⚫ | |||
/*─────────────────────────────────────setSC subroutine─────────────────*/ |
|||
⚫ | |||
⚫ | |||
║ characters can be used, including blank(s) and non─displayable ║ |
|||
║ characters (including '00'x, 'ff'x, commas, periods, quotes, ···).║ |
|||
╚════════════════════════════════════════════════════════════════════╝*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
{{out}} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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> |
<pre> |
||
the former capital of (AL) Alabama was Tuscaloosa |
the former capital of (AL) Alabama was Tuscaloosa |