AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Difference between ++var and var++ ? (https://forums.alliedmods.net/showthread.php?t=171975)

kotinha 11-13-2011 08:49

Difference between ++var and var++ ?
 
As the title says, what is the difference between doing ++var and var++ ?

I've been searching but found nothing...

Flipper_SPb 11-13-2011 09:12

Re: Difference between ++var and var++ ?
 
preincrement
x = ++var
means:
PHP Code:

var = var + 1
= var 

postincrement
x = var++
means:
PHP Code:

= var
var = var + 



Arkshine 11-13-2011 09:48

Re: Difference between ++var and var++ ?
 
You can find the answer here too : http://wiki.amxmodx.org/Pawn_Tutorial#Expressions

kotinha 11-13-2011 10:05

Re: Difference between ++var and var++ ?
 
So, it works like this?:
PHP Code:

new var1 10
new var2 var1++ // var2 = 10 and var1 = 11 ?
// -------
new var1 10
new var2 = ++var1 // var2 = 11 and var1 = 11 ? 


Bugsy 11-13-2011 10:07

Re: Difference between ++var and var++ ?
 
It determines the return value of var; var++ gives you the value prior to the increment while ++var gives you the value after the increment.

var = 10
x = var++
x = 10, var = 11

var = 10
x = ++var
x = 11, var = 11

kotinha 11-13-2011 10:29

Re: Difference between ++var and var++ ?
 
Alright, got it :)
Thanks


All times are GMT -4. The time now is 08:25.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.