The reason I use `while` here is that I need the `i` afterwards to put all the leftover task back in the queue.