Search a list: Difference between revisions

m
Move FutureBasic out of BASIC group
m (Move FutureBasic out of BASIC group)
Line 545:
Bush found first at index 5
Bush found last at index 8
</pre>
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">
window 1, @"Search a list"
 
void local fn MyEnumeratorCallback( array as CFArrayRef, obj as CFTypeRef, index as NSUInteger, stp as ^BOOL, userData as ptr )
if ( fn StringIsEqual( obj, userData ) )
print obj;@" found at index ";index
*stp = YES// stop enumeration
end if
if ( index == 0 ) then print userData;@" not found"
end fn
 
void local fn DoIt
CFArrayRef haystack = @[@"Mike",@"Bravo",@"Tango",@"Uniform",@"Golf",
@"Tango",@"Sierra",@"November",@"Zulu",@"Delta",@"Hotel",@"Juliet"]
CFStringRef needle = @"Sierra"
NSInteger index = fn ArrayIndexOfObject( haystack, needle )
if ( index != NSNotFound )
print needle;@" found at index ";index
else
print needle;@" not found"
end if
ArrayEnumerateObjectsWithOptions( haystack, NSEnumerationReverse, @fn MyEnumeratorCallback, (ptr)@"Tango" )
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
{{out}}
<pre>
Sierra found at index 6
Tango found at index 5
</pre>
 
Line 1,740 ⟶ 1,702:
 
end program main</syntaxhighlight>
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">
window 1, @"Search a list"
 
void local fn MyEnumeratorCallback( array as CFArrayRef, obj as CFTypeRef, index as NSUInteger, stp as ^BOOL, userData as ptr )
if ( fn StringIsEqual( obj, userData ) )
print obj;@" found at index ";index
*stp = YES// stop enumeration
end if
if ( index == 0 ) then print userData;@" not found"
end fn
 
void local fn DoIt
CFArrayRef haystack = @[@"Mike",@"Bravo",@"Tango",@"Uniform",@"Golf",
@"Tango",@"Sierra",@"November",@"Zulu",@"Delta",@"Hotel",@"Juliet"]
CFStringRef needle = @"Sierra"
NSInteger index = fn ArrayIndexOfObject( haystack, needle )
if ( index != NSNotFound )
print needle;@" found at index ";index
else
print needle;@" not found"
end if
ArrayEnumerateObjectsWithOptions( haystack, NSEnumerationReverse, @fn MyEnumeratorCallback, (ptr)@"Tango" )
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
{{out}}
<pre>
Sierra found at index 6
Tango found at index 5
</pre>
 
=={{header|GAP}}==
416

edits