Correct. When you say, for example:
_g = units (leader (_eGroups select _i))
The local variable _i must be defined before this command is used. _i can be used to represent anything, but in this case, it needs to represent 0.
So, when the script starts, I put:
_i = 0
So, the _i variable is defined.
When you're using if/then and ?/:, what you must remember is that if the condition is not met by the time the script reaches that point, it won't wait until the condition is met. Example:
? not (alive captain): player sidechat "We need a medic over here!"
In this example, if when the script gets to that condition, and the captain is not dead, the script won't just stop until the condition is made true.
Unless, you use a loop, or the @ command.
But, for simple conditions like checking when a loon is dead, or when a vehicle is destroyed, you could just use a trigger in-game.
I try to avoid using many looping scripts if I can help it. I'll also destroy triggers after their condition has been met (unless they're set to repeatedly). Triggers that have been....triggered, are no longer of any use unless they have been set to repeat.
Anyway, I digress.
Hope that answers your questions