"Goes To" operator: --> -
Y_Less - 27.12.2018
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...
Re: "Goes To" operator: --> -
coool - 27.12.2018
Interesting
Re: "Goes To" operator: --> -
Whyd - 27.12.2018
A little stupid but interesting, thank you!
Re: "Goes To" operator: --> -
Hunud - 27.12.2018
Would it be possible to make with this a some kind of 'countdown' without using the timers or whatever.
Re: "Goes To" operator: --> -
Freaksken - 27.12.2018
Quote:
Originally Posted by Hunud
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.
Re: "Goes To" operator: --> -
DarkBr - 27.12.2018
Weird, though interesting.
Re: "Goes To" operator: --> -
iLearner - 28.12.2018
Indeed interesting!
Re: "Goes To" operator: --> -
NaS - 28.12.2018
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.
Re: "Goes To" operator: --> -
DAKYSKYE - 29.12.2018
Weird but interesting
Re: "Goes To" operator: --> -
Eoussama - 29.12.2018
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.
Re: "Goes To" operator: --> -
Hreesang - 25.02.2019
I've been looking for this months ago.
*jejak*