auto increment loop not working

It is not nice to update a for loop control variable in the for loop

timer=0;

This is rather odd. Under what circumstances do you think this if statement is/is not going to be true ?

if (timer/1000){
 . . . 
}