Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 What does += mean?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
CheshireFox




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sat Mar 22, 2014 7:32 pm   Post subject: RE:What does += mean?

Why not try it out?
CheshireFox




PostPosted: 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)
Insectoid




PostPosted: 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.
CheshireFox




PostPosted: Sat Mar 22, 2014 7:42 pm   Post subject: Re: What does += mean?

if I insert put then an error appears.
GreatPumpkin




PostPosted: 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
CheshireFox




PostPosted: 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.
GreatPumpkin




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: 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)
Dreadnought




PostPosted: 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.
Raknarg




PostPosted: Sat Mar 22, 2014 11:54 pm   Post subject: RE:What does += mean?

Good point, forgot about those
Dreadnought




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: