1) Depends on the content of your array. If it is an array with unsorted data, then the second solution should be slightly better, but not by much. If it's sorted then doing a binary search would probably be better.
2) The first counter is local to the scope of xxx(), while the for loops counter is only local to the for loop. quick example:
Lua Code:
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> do
>> local c = 0
>> for c=1, 3 do print(c) end
>> print(c)
>> end
1
2
3
0
3) You can do it by tracking changes to the HP through the combat log or through someones target. No directly easy way to track such when there's no valid unit id to track.