What is this ++ thing? 'x++'

Im following BergZerg Arcade tutorial and before then I keep coming across this ++ thing, what is it? I think its someone to do with adding, but adding what?

I suspect its adding something to the variable x
(Same case with y)

public bool Dragable = true;
public Rect InvWindowRect = new Rect (10, 10, 170, 265);
	public int InvRows = 7;
	public int InvColumns = 4;
	public int ButtonWidth = 40;
	public int ButtonHeight = 40;

public void InventoryWindow(int id)
	{
		for (int x = 0; x < InvRows; x++)
		{
			for(int y = 0; y < InvColumns; y++)
			{
				GUI.Button(new Rect(5 + (x * ButtonWidth), 20 + (y * ButtonHeight), ButtonWidth, ButtonHeight), (x + y * InvColumns).ToString());
			}
		}
		if (Dragable) 
		{
			GUI.DragWindow(/*new Rect(10, 2, 0, 0)*/);
		}

Update:
Ok I looked into it more, does it mean that each time that line is executed, it adds 1 to the value of x?
So for the first time if x = 0 and x++ is executed it will add 1 and its passed a second time and adds another 1 to the value so it would be 2 and so on.
Is this correct?

1 Like

x++ =
x = x+1

3 Likes

Yeah,

Like dterbeest said (Although I feel it needed more clarity), basically it increments the value by one. So if it had 16 in there before x++ was run, it would increment to 17 afterwards. In this case its to control the amount of times the code is run, Making sure not to throw any errors by referencing objects that don’t exist.

1 Like

x++ add one to x afterwards
x-- take one from x afterwards
++x add one to x before
–x take one from x before

++ operator

– operator

thats general C# code reference, but the concept is the same in pretty much all programming languages that support these operators. You add/subtract one either before or after using the number.

3 Likes

Thanks Guys! :smile: been bugging me ever since i started c#

1 Like