explanation
#1

Hey if I have a variable and I type like this in a function
Код:
...
SomeVar[somevar]++;
..
What does the ++ do? Can we make something else instead of that ++?
Reply
#2

This adds +1 to the variable.

Here are different instances of using ++:
pawn Код:
// SomeVar[somevar] is 0

SomeVar[somevar]++;

// SomeVar[somevar] will be 1 now



// SomeVar[somevar] is 0

++SomeVar[somevar];

// SomeVar[somevar] will be 1 now
pawn Код:
// SomeVar[somevar] is 0

printf("%i", SomeVar[somevar]++);

// System will print "0" but SomeVar[somevar] is "1" (SomeVar[somevar] value is taken first and then +1 is added)


pawn Код:
// SomeVar[somevar] is 0

printf("%i", ++SomeVar[somevar]);

// System will print "1" and SomeVar[somevar] is "1" as well (+1 is added first and then SomeVar[somevar] is taken)
Reply
#3

Thanks.
Reply
#4

Instead of ++ you can do

Somevar[somevar] = Somevar[somevar] + 1;

or also

Somevar[somevar] += 1;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)