correct variable usage in loops