5

Recently, I came across a code where --> was used.

example:

int a = 5;
while(a-->0){
    //do something 'a' times
}

Is (a-->0) equivalent to (a-- > 0) or simply, ((a=a-1) > 0)?

If not, I want to know what's that operator called, and are there other similar operators. If so, then where are they mentioned?

Thanks

xploreraj
  • 3,792
  • 12
  • 33
  • 51

1 Answers1

9

It's two operations. The postfix -- (a = a - 1 but effective on the next line) and a greater than. It's equivalent to something like

while (a > 0) {
    a = a - 1;
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • Ya, I guessed so!! The confusion stemmed from Intelij where, sometimes anonymous Runnables are folded with -> symbols!! – xploreraj Feb 13 '16 at 23:33
  • I think the language(s) should mark this as an error. Operators should be space delimited unless connected to a literal or name. –  Dec 16 '19 at 19:03