Author |
Message |
CheshireFox
|
Posted: Sat Mar 22, 2014 7:30 pm Post subject: What does += mean? |
|
|
As the topic stated above, what does += mean?
Thanks in advance to anyone who replies |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sat Mar 22, 2014 7:32 pm Post subject: RE:What does += mean? |
|
|
Why not try it out? |
|
|
|
|
![](images/spacer.gif) |
CheshireFox
|
Posted: Sat Mar 22, 2014 7:37 pm Post subject: Re: What does += mean? |
|
|
I did...though when i run it nothing happens....(the run window doesn't even open) |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sat Mar 22, 2014 7:38 pm Post subject: 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. |
|
|
|
|
![](images/spacer.gif) |
CheshireFox
|
Posted: Sat Mar 22, 2014 7:42 pm Post subject: Re: What does += mean? |
|
|
if I insert put then an error appears. |
|
|
|
|
![](images/spacer.gif) |
GreatPumpkin
|
Posted: Sat Mar 22, 2014 8:07 pm Post subject: Re: What does += mean? |
|
|
Turing: |
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:
Turing: |
var number2 : int := 2
var number1 : int
number1 := 5
put number1
number1 += number2
put number1
|
|
|
|
|
|
![](images/spacer.gif) |
CheshireFox
|
Posted: Sat Mar 22, 2014 8:13 pm Post subject: Re: What does += mean? |
|
|
Thank you! You wrote it in a very easy to understand way with examples. |
|
|
|
|
![](images/spacer.gif) |
GreatPumpkin
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Sat Mar 22, 2014 10:54 pm Post subject: 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) |
|
|
|
|
![](images/spacer.gif) |
Dreadnought
|
Posted: Sat Mar 22, 2014 11:51 pm Post subject: Re: What does += mean? |
|
|
Raknarg wrote:
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
Turing: | 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. |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Sat Mar 22, 2014 11:54 pm Post subject: RE:What does += mean? |
|
|
Good point, forgot about those |
|
|
|
|
![](images/spacer.gif) |
Dreadnought
|
Posted: Sun Mar 23, 2014 12:03 am Post subject: Re: What does += mean? |
|
|
Raknarg wrote:
Good point, forgot about those
I only just found out about **= when I tried it out. ![Razz Razz](http://compsci.ca/v3/images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
|