Skip to content


Lol – The ‘down to’ operator

Last week, I ran across this blogpost about an undocumented operator called the ‘down to’ operator.

var a:uint = 20;
while ( a --> 0 ) trace(a);

This will trace out the numbers 20 through 1 in the Output panel.

I’d never heard of this, so I tried it out. It worked as stated, but I couldn’t find _anything_ about it anywhere but this post.

I wanted to use this operator this morning, but from a slightly different angle, so I started researching the ‘down to’ operator, again to see if it was possible to do what I wanted to do. And also just to see what all it was supposed to do.

Came back to the same post – but this time I noticed that he learned out this secret operator from a StackOverflow question, so started looking through that thread – in doing so, I found this related question, which contained a comment which sorted things out.

The deal is that this is NOT an undocumented operator. It’s two totally documented operators with the whitespace removed (-- and >).

while (a --> 0)

is actually while (a-- > 0)



Really had me going because I was doing this:

var f:int = versionListExclusions.length - 1;
while(f --> 0)
{
if(subDirectory == versionListExclusions[f])
...

‘versionListExclusions’ is an Array, and I was getting one less iteration out of the while loop than I was expecting – cause the first thing I was actually doing was decrementing the value of ‘f’.

Correct usage is:

var f:int = versionListExclusions.length;
while(f --> 0)
{
if(subDirectory == versionListExclusions[f])
...

Though, really, truly correct usage is:

var f:int = versionListExclusions.length;
while(f-- > 0)
{
if(subDirectory == versionListExclusions[f])
...

HAHA. LOL. -1 HOUR OF MY LIFE.

Posted in Ouch.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.