Search a list: Difference between revisions

Content added Content deleted
mNo edit summary
Line 2,227: Line 2,227:
(%i37) catch(findneedle("Zag", haystack, 'l));
(%i37) catch(findneedle("Zag", haystack, 'l));
(%o37) 7</pre>
(%o37) 7</pre>

=={{header|Nanoquery}}
{{trans|Python}}
<lang Nanoquery>$haystack = list()
append $haystack "Zig" "Zag" "Wally" "Ronald" "Bush" "Krusty" "Charlie"
append $haystack "Bush" "Bozo"

$needles = list()
append $needles "Washington"
append $needles "Bush"

for ($i = 0) ($i < len($needles)) ($i = $i + 1)
$needle = $needles[$i]
try
// use array lookup syntax to get the index of the needle
println $haystack[$needle] + " " + $needle
catch
println $needle + " is not in haystack"
end
end for</lang>
{{out}}
<pre>Washington is not in haystack
4 Bush</pre>


=={{header|NetRexx}}==
=={{header|NetRexx}}==