In various codes where time limit exceeded, by using while(t-- >0) instead of while(t--) code runs successfully. I don't know about while(t-- >0) , I read it somewhere in the codechef examples solution.
Asked
Active
Viewed 528 times
-2
-
It's different if `t` can be negative. – interjay Apr 25 '21 at 14:57
-
The (inexistent) difference should not matter for "time limit exceeded". Something other is the reason for failing or not. – pmg Apr 25 '21 at 14:57
1 Answers
-1
In practice, they are equivalent. It's just a matter of taste. Some think that while(t-- > 0)
is clearer than while(t--)
.
As long as t
is not negative, the two are completely equivalent. But on the other hand, a negative t
would most likely indicate a bug with a loop like that.

klutt
- 30,332
- 17
- 55
- 95