37 lines
899 B
Text
37 lines
899 B
Text
haystack$="apple orange pear cherry melon peach banana needle blueberry mango strawberry needle "
|
|
haystack$=haystack$+"pineapple grape kiwi blackberry plum raspberry needle cranberry apricot"
|
|
|
|
idx=1
|
|
do until word$(haystack$,idx)=""
|
|
idx=idx+1
|
|
loop
|
|
total=idx-1
|
|
|
|
needle$="needle"
|
|
'index of first occurrence
|
|
for i = 1 to total
|
|
if word$(haystack$,i)=needle$ then exit for
|
|
next
|
|
print needle$;" first found at index ";i
|
|
|
|
'index of last occurrence
|
|
for j = total to 1
|
|
if word$(haystack$,j)=needle$ then exit for
|
|
next
|
|
print needle$;" last found at index ";j
|
|
if i<>j then
|
|
print "Multiple instances of ";needle$
|
|
else
|
|
print "Only one instance of ";needle$;" in list."
|
|
end if
|
|
|
|
'raise exception
|
|
needle$="cauliflower"
|
|
for k=1 to total
|
|
if word$(haystack$,k)=needle$ then exit for
|
|
next
|
|
if k>total then
|
|
print needle$;" not found in list."
|
|
else
|
|
print needle$;" found at index ";k
|
|
end if
|