Resolve variables in a loop