Why does this while loop give me an error?

Actually, you can use delays like that: a delay is called once and cannot be called again until the countdown is over, it’s sometimes quite handy. The thing is, if the operation is only performed once a second, there’s no sense in using a while loop; a looping timer with 1-second interval should do.