optimize access to loop, key and value variables

small optimization variable access (loop, key and value) inside for loop