Task[edit]
Find the index of a string (needle) in an indexable, ordered collection of strings (haystack).

Raise an exception if the needle is missing.

If there is more than one occurrence then return the smallest index to the needle.

Extra credit
Return the largest index to a needle that has multiple occurrences in the haystack.

See also
 Search a list of records

haystack$ = ("Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo Bush ")
needle$   = "Zag Wally Bush Chicken"
 
while word$(needle$,i+1," ") <> ""
  i  = i + 1
  thisNeedle$ = word$(needle$,i," ") + " "
  j  = instr(haystack$,thisNeedle$)
  k1 = 0
  k  = instr(haystack$,thisNeedle$,j+1) 
  while k <> 0
    k1 = k
    k  = instr(haystack$,thisNeedle$,k+1) 
  wend
  if j <> 0 then  
    print thisNeedle$;" located at:";j; 
    if k1 <> 0 then print " Last position located at:";k1;
    print 
   else 
    print thisNeedle$;" is not in the list"
  end if
wend