Problem updating a variable in a loop

now its working