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

#! /usr/bin/awk -f
BEGIN {
    # create the array, using the word as index...
    words="Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo";
    split(words, haystack_byorder, " ");
    j=0;
    for(idx in haystack_byorder) {
	haystack[haystack_byorder[idx]] = j;
	j++;
    }
    # now check for needle (we know it is there, so no "else")...
    if ( "Bush" in haystack ) {
	print "Bush is at " haystack["Bush"];
    }
    # check for unexisting needle
    if ( "Washington" in haystack ) {
	print "impossible";
    } else {
	print "Washington is not here";
    }
}