Prefix/Postfix - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Prefix/Postfix (
/showthread.php?tid=621372)
Prefix/Postfix -
DTV - 10.11.2016
I was reading a tutorial about the different type of loop structures (
Link) and noticed something talking about prefix and postfix. The only difference it mentioned about the two was that it evaluated the operator before the variable and vice versa.
Код:
--myVariable //prefix
myVariable-- //postfix
Other than what they explained as the difference was, is there any other differences that would make it more efficient/useful in one set of conditions than in others?
Re: Prefix/Postfix -
Micko123 - 10.11.2016
Nope. I think not. It is same using --something or something-- as far as I know
Re: Prefix/Postfix -
PrO.GameR - 10.11.2016
No, those more differ in the usage than efficiency, if you check if --variable<10, that means variable will be 9 as you will be deducting it before the comparison, if you use variable--<10, variable will be 8 when loop stops as you first compare then deduct.
Re: Prefix/Postfix -
RoboN1X - 10.11.2016
Код:
new a = 0; // a = 0
printf("%d", a++); // prints a = "0", increase a +1
new b = 0; // b = 0
printf("%d", ++b); // increase b + 1, prints b = "1"
I think nothing different to compare by efficiency, but that will be useful in function to write a fewer line for example, i increased variable and convert it to string.
Код:
++variable;
valstr(string, variable);
To:
Код:
valstr(string, ++variable);
Or vice versa:
Код:
valstr(string, variable);
variable++;
To:
Код:
valstr(string, variable++);
Sorry for my bad english.
Re: Prefix/Postfix -
SyS - 10.11.2016
The only difference between prefix and postfix operators is in the result of these. In postfix, a temporary object is created, the operation is applied, and the temporary is returned: the object before the operation is applied. In prefix, the operation is applied and the fixed object is returned,
without the use of a temporary: the object after the operation is applied.