Extract variable out of loop

Extract variable out of loop