Associative array/Iteration: Difference between revisions

add FreeBASIC
(add FreeBASIC)
Line 1,314:
Ruby invented by: Matsumoto, Yukihiro
count: 10
</pre>
 
=={{header|FreeBASIC}}==
 
Use the typedefs and data from [[Associative Array/Creation#FreeBASIC]] as an include.
 
Since this data structure stores the keys and values together it makes little sense to iterate through the same array three times to print different parts of it, hence I will only print the key:value pairs.
 
<lang freebasic>#include"assoc.bas"
 
function get_dict_data_string( d as dicitem ) as string
select case d.datatype
case BOOL
if d.value.bool then return "true" else return "false"
case INTEG
return str(d.value.integ)
case STRNG
return """"+d.value.strng+""""
case FLOAT
return str(d.value.float)
case BYYTE
return str(d.value.byyte)
case else
return "DATATYPE ERROR"
end select
end function
 
sub print_keyval_pair( d as dicentry )
print using "{&} : {&}";get_dict_data_string( d.key ); get_dict_data_string(d.value)
end sub
 
for i as uinteger = 0 to ubound(Dictionary)
print_keyval_pair(Dictionary(i))
next i</lang>
 
{{out}}
<pre>
{"Cat"} : {"Mittens"}
{32767} : {2.718281828}
</pre>
 
781

edits