how to switch off led in Loop

Work out what happens when your timer variable is actually equal to 1 - which 'if' applies in your current code?

Better practice in this case is to have

if (time == 0)
{
  // do stuff
}
else
{
  // do otherstuff
}

which was probably your intention anyway.