
-----------------------------------
CheshireFox
Sat Mar 22, 2014 7:30 pm

What does += mean?
-----------------------------------
As the topic stated above, what does += mean? 

Thanks in advance to anyone who replies

-----------------------------------
Insectoid
Sat Mar 22, 2014 7:32 pm

RE:What does += mean?
-----------------------------------
Why not try it out?

-----------------------------------
CheshireFox
Sat Mar 22, 2014 7:37 pm

Re: What does += mean?
-----------------------------------
I did...though when i run it nothing happens....(the run window doesn't even open)

-----------------------------------
Insectoid
Sat Mar 22, 2014 7:38 pm

RE:What does += mean?
-----------------------------------
You can't see what happens if you don't output something. Try using the put command after you use it.

-----------------------------------
CheshireFox
Sat Mar 22, 2014 7:42 pm

Re: What does += mean?
-----------------------------------
if I insert put then an error appears.

-----------------------------------
GreatPumpkin
Sat Mar 22, 2014 8:07 pm

Re: What does += mean?
-----------------------------------

var number : int
number := 5
put number
number += 1
put number


Try that.

You'll notice it's essentially the same thing as:
number := number + 1

It's a shortcut for adding what comes after to the variable being operated on.

You can also use it in operations with other variables:



var number2 : int := 2
var number1 : int
number1 := 5
put number1
number1 += number2
put number1


-----------------------------------
CheshireFox
Sat Mar 22, 2014 8:13 pm

Re: What does += mean?
-----------------------------------
Thank you! You wrote it in a very easy to understand way with examples.

-----------------------------------
GreatPumpkin
Sat Mar 22, 2014 9:47 pm

Re: What does += mean?
-----------------------------------
You're welcome, check out the Turing Walkthrough: http://compsci.ca/v3/viewtopic.php?t=8808

-----------------------------------
Raknarg
Sat Mar 22, 2014 10:54 pm

RE:What does += mean?
-----------------------------------
Other shorthands: 

a /= b is the same as a := a/b
a *= b is the same as a := a*b
a -= b is the same as a := a-b
a ~= b is the same as not(a = b)

-----------------------------------
Dreadnought
Sat Mar 22, 2014 11:51 pm

Re: What does += mean?
-----------------------------------

Other shorthands 

a /= b is the same as a = a/b
a *= b is the same as a = a*b
a -= b is the same as a = a-b
a ~= b is the same as not(a = b)

There's one for almost every operator you can think of
a **= b  % a := a ** b
a div= b  % a := a div b
a rem= b  % a := a rem b
a mod= b  % a := a mod b
a |= b  % a := a | b (bitwise OR)
a &= b  % a := a & b (bitwise AND)
a xor= b  % a := a xor b

I think that along with the above that's all of them.

Notice that since a occurs once in one form and twice in the other, it is possible for the behaviors to be different if a has some kind of side-effect associated to it.

-----------------------------------
Raknarg
Sat Mar 22, 2014 11:54 pm

RE:What does += mean?
-----------------------------------
Good point, forgot about those

-----------------------------------
Dreadnought
Sun Mar 23, 2014 12:03 am

Re: What does += mean?
-----------------------------------

Good point, forgot about those

I only just found out about **= when I tried it out. :P
