Associative array/Iteration: Difference between revisions
Content added Content deleted
(FutureBasic solution added) |
m (→{{header|FutureBasic}}: More options added) |
||
Line 1,422: | Line 1,422: | ||
=={{header|FutureBasic}}== |
=={{header|FutureBasic}}== |
||
There are many ways to iterate over an associative array (dictionary) in FutureBasic. Below are a |
There are many ways to iterate over an associative array (dictionary) in FutureBasic. Below are a selection. |
||
<syntaxhighlight lang="futurebasic"> |
<syntaxhighlight lang="futurebasic"> |
||
void local fn DoIt |
void local fn DoIt |
||
Line 1,438: | Line 1,438: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<syntaxhighlight lang="futurebasic"> |
|||
void local fn MyDictEnumerator( dict as CFDictionaryRef, key as CFTypeRef, obj as CFTypeRef, stp as ^BOOL, userData as ptr ) |
|||
print key, obj |
|||
end fn |
|||
void local fn DoIt |
|||
CFDictionaryRef dict = @{@"A":@"Alpha", @"B":@"Bravo", @"C":@"Charlie", @"D":@"Delta"} |
|||
DictionaryEnumerateKeysAndObjects( dict, @fn MyDictEnumerator, NULL ) |
|||
end fn |
|||
fn DoIt |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="futurebasic"> |
|||
void local fn DoIt |
|||
CFDictionaryRef dict = @{@"A":@"Alpha", @"B":@"Bravo", @"C":@"Charlie", @"D":@"Delta"} |
|||
CFArrayRef keys = fn DictionaryAllKeys( dict ) |
|||
CFStringRef key |
|||
for key in keys |
|||
print key, dict[key] |
|||
next |
|||
end fn |
|||
fn DoIt |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="futurebasic"> |
|||
void local fn DoIt |
|||
CFDictionaryRef dict = @{@"A":@"Alpha", @"B":@"Bravo", @"C":@"Charlie", @"D":@"Delta"} |
|||
CFArrayRef values = fn DictionaryAllValues( dict ) |
|||
CFStringRef value |
|||
for value in values |
|||
print value |
|||
next |
|||
end fn |
|||
fn DoIt |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="futurebasic"> |
|||
void local fn DoIt |
|||
CFDictionaryRef dict = @{@"A":@"Alpha", @"B":@"Bravo", @"C":@"Charlie", @"D":@"Delta"} |
|||
CFStringRef key |
|||
CFTypeRef obj |
|||
EnumeratorRef keyEnumerator = fn DictionaryKeyEnumerator( dict ) |
|||
key = fn EnumeratorNextObject( keyEnumerator ) |
|||
while ( key ) |
|||
print key,dict[key] |
|||
key = fn EnumeratorNextObject( keyEnumerator ) |
|||
wend |
|||
print |
|||
EnumeratorRef objectEnumerator = fn DictionaryObjectEnumerator( dict ) |
|||
obj = fn EnumeratorNextObject( objectEnumerator ) |
|||
while ( obj ) |
|||
print obj |
|||
obj = fn EnumeratorNextObject( objectEnumerator ) |
|||
wend |
|||
end fn |
|||
fn DoIt |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
=={{header|Gambas}}== |
=={{header|Gambas}}== |