modify external variable inside selection looping