Posts: 547
Threads: 57
Joined: Dec 2010
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?
Posts: 1,199
Threads: 238
Joined: Feb 2016
Reputation:
0
Nope. I think not. It is same using --something or something-- as far as I know
Posts: 694
Threads: 2
Joined: Oct 2012
Reputation:
0
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.
Posts: 1,939
Threads: 11
Joined: Oct 2015
Reputation:
0
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.