Jump to content

Associative array/Iteration: Difference between revisions

Added the CONTAINSKEY operator needed by the Lychrel Numbers task.
m (→‎{{header|ooRexx}}: add output)
(Added the CONTAINSKEY operator needed by the Lychrel Numbers task.)
Line 84:
array
END; # INIT #
 
# gets a reference to the value corresponding to a particular key in an #
# associative array - the element is created if it doesn't exist #
Line 121 ⟶ 122:
result
END; # // #
 
# returns TRUE if array contains key, FALSE otherwise #
PRIO CONTAINSKEY = 1;
OP CONTAINSKEY = ( REF AARRAY array, AAKEY key )BOOL:
BEGIN
# get the hash chain for the key #
REF AAELEMENTLIST element := ( elements OF array )[ HASH key ];
# find the element in the list, if it is there #
BOOL found element := FALSE;
WHILE ( element ISNT nil element list )
AND NOT found element
DO
found element := ( key OF element OF element = key );
IF NOT found element
THEN
element := next OF element
FI
OD;
found element
END; # CONTAINSKEY #
 
# gets the first element (key, value) from the array #
3,049

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.