Computer Science Canada What does += mean? |
Author: | CheshireFox [ 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 |
Author: | Insectoid [ Sat Mar 22, 2014 7:32 pm ] |
Post subject: | RE:What does += mean? |
Why not try it out? |
Author: | CheshireFox [ 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) |
Author: | Insectoid [ 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. |
Author: | CheshireFox [ Sat Mar 22, 2014 7:42 pm ] |
Post subject: | Re: What does += mean? |
if I insert put then an error appears. |
Author: | GreatPumpkin [ Sat Mar 22, 2014 8:07 pm ] | ||||
Post subject: | Re: What does += mean? | ||||
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:
|
Author: | CheshireFox [ 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. |
Author: | GreatPumpkin [ Sat Mar 22, 2014 9:47 pm ] |
Post subject: | Re: What does += mean? |
You're welcome, check out the Turing Walkthrough: http://compsci.ca/v3/viewtopic.php?t=8808 |
Author: | Raknarg [ 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) |
Author: | Dreadnought [ 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
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. |
Author: | Raknarg [ Sat Mar 22, 2014 11:54 pm ] |
Post subject: | RE:What does += mean? |
Good point, forgot about those |
Author: | Dreadnought [ 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. ![]() |