It is clearly defining the behavior of the linked program, and not knowing it would evaluate like that would probably be the source of another off-by-one error.
Because making it so that's significant behaviour is more likely to result in errors than making distinct statements and makes it harder to modify the code for special cases that may exist in the future.
Like the more clear way of writing this would be
for (x = 9; x >= 0; x--)
This clearly shows that 9 is the first value of x in the loop, it stops when x goes negative and each time x goes down by 1.
Not quite. It decrements then performs the comparison with the non decremented value. The decrement always happens before the comparison, but whether it compares with the current or previous value of x depends on the use of prefix or postfix decrement.
317
u/PityUpvote Feb 21 '20
uj/ for anyone not getting it, it's interpreted as
while (x-- > 0)86
u/[deleted] Feb 21 '20
I'm still surprised I don't use that "operator". It does what it looks like it does and it's a better looking alternative to normal
for's78
u/lengau Feb 21 '20
Looks simple enough to me. It's the "approaches" operator.
There's also the "approaches quickly" operator (
---->).•
u/Synx Feb 21 '20
Wrong sub, but it's Friday so let's let it roll.
21
u/[deleted] Feb 21 '20 edited Apr 13 '26
Databrokers? nope. Social networks? Also nope. This post was deleted using Redact.
exultant grab like versed cover memorize automatic encouraging payment snow
34
u/ten3roberts Feb 21 '20
Why would the --> operator be considered bad code? And why would there be a surprise it compiled?
7
u/Delta_Ryu Feb 21 '20
20 --> 10
10
u/sintos-compa Feb 21 '20
Hahahahahaa ngl it had be in the first 3/4
15
u/flarn2006 Feb 21 '20
Why not link to the full page?
https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c
3
u/vegetaman Feb 21 '20
Surprised they didn't gripe that it wasn't 10 thru 1 instead of 9 thru 0 lmao.