[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


Messages In This Thread
"Goes To" operator: --> - by Y_Less - 27.12.2018, 14:27
Re: "Goes To" operator: --> - by coool - 27.12.2018, 14:30
Re: "Goes To" operator: --> - by Whyd - 27.12.2018, 14:53
Re: "Goes To" operator: --> - by Hunud - 27.12.2018, 14:58
Re: "Goes To" operator: --> - by Freaksken - 27.12.2018, 15:41
Re: "Goes To" operator: --> - by DarkBr - 27.12.2018, 16:20
Re: "Goes To" operator: --> - by iLearner - 28.12.2018, 09:06
Re: "Goes To" operator: --> - by NaS - 28.12.2018, 09:07
Re: "Goes To" operator: --> - by DAKYSKYE - 29.12.2018, 13:14
Re: "Goes To" operator: --> - by Eoussama - 29.12.2018, 13:22
Re: "Goes To" operator: --> - by Hreesang - 25.02.2019, 01:54

Forum Jump:


Users browsing this thread: 6 Guest(s)