Do you use i-->0 for backward loops?

Posted by maaartinus on Programmers See other posts from Programmers or by maaartinus
Published on 2011-04-25T20:07:58Z Indexed on 2012/11/14 11:18 UTC
Read the original article Hit count: 208

Filed under:

Some people write

for (int i=N; i-->0; ) doSomething(i);

instead of

for (int i=N-1; i>=0; --i) doSomething(i);

for backward loops. The --> "operator"1 looks very confusing at the first glance, but it's trivial:
i-->0 simply parses as (i--)>0, and once you get it, you see it immediately.

The main disadvantage is the strange look. The advantage is that you'll get it always right (unlike the more verbose version offering the possibility to forget something, which really happened to me a couple of times).

What do you think about using the --> "operator"?


1First time I saw the funny term in a comment to this question today.

© Programmers or respective owner

Related posts about syntax