[Tutorial] "Goes To" operator: -->
#1

Goes To
Just a brief tutorial to tell people about the “goes to” operator: -->. The arrow design is to show it goes towards the number, thus it decrements a variable until it reaches zero, and can be used in loops to loop a number of times. Mainly the while loop:

Code:
new i = 10;
while (i --> 0)
{
    printf("%d", i);
}
Will print:

9
8
7
6
5
4
3
2
1
0


Note that 10 is not included, while 0 is. This makes it like normal loops, but backwards.

You can loop over players backwards with:

Code:
for (new i = MAX_PLAYERS; i --> 0; )
{
}
Technically you can go down to any value:

Code:
new j = 10;
while (j --> 5) {}
And yes, if you haven’t figured it out yet, this isn’t actually a new operator. It is two operators (-- and >) with odd spacing. That last example would be more normally written as:

Code:
new j = 10;
while (j-- > 5) {}
I first saw this here: https://stackoverflow.com/questions/...-operator-in-c so though I’d write it here. It is stupid, don't use it...
Reply
#2

Interesting
Reply
#3

A little stupid but interesting, thank you!
Reply
#4

Would it be possible to make with this a some kind of 'countdown' without using the timers or whatever.
Reply
#5

Quote:
Originally Posted by Hunud
View Post
Would it be possible to make with this a some kind of 'countdown' without using the timers or whatever.
What? It's just normal looping behaviour with a stranger syntax.
Reply
#6

Weird, though interesting.
Reply
#7

Indeed interesting!
Reply
#8

Nice.

Now I'll always omit spaces between an operator and a comparator to make it look like I found a new operator!

We should call them "comperator".

Still nice find, since it's the only combination that looks like what it actually does.
Reply
#9

Weird but interesting
Reply
#10

It took me longer to realize it wasn't some new introduced operator, really interesting and I bet there could be multiple cases of the same trick.
Reply
#11

I've been looking for this months ago.

*jejak*
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)