Code udpated for handling loop iterator as var