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

Username:   Password: 
 RegisterRegister   
 Kind of Stupid Question (+=,-=)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mr.Programmer




PostPosted: Wed Feb 27, 2008 7:15 pm   Post subject: Kind of Stupid Question (+=,-=)

My question is, what do these two things mean: ' += ' and ' -="?

I know that := means 'becomes', but these two i cant figure out. Here's an example:

vely -= GRAVITY
posx += round (velx)
posy += round (vely)

Thanks!
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Feb 27, 2008 7:24 pm   Post subject: RE:Kind of Stupid Question (+=,-=)

var += 42
is the short way of saying
var := var + 42
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Mr.Programmer




PostPosted: Wed Feb 27, 2008 7:26 pm   Post subject: Re: Kind of Stupid Question (+=,-=)

Ohhh. Then i guess var -= 22 is like saying ' var :+ var - 22 '?

If so then it makes sense.

And thank you very much.
Bored




PostPosted: Thu Feb 28, 2008 7:26 pm   Post subject: Re: Kind of Stupid Question (+=,-=)

There's also other including *=, /=, div=, and I beleive there might be more that I'm missing.
BigBear




PostPosted: Thu Feb 28, 2008 7:34 pm   Post subject: Re: Kind of Stupid Question (+=,-=)

when you use := it means becomes or is therefore equal to and when you use += it means becomes itself plus whatever is next
code:
So
var word : string := "" %declares it as nothing
word := word +"hello" %is the same as
word+=word

-= means becomes itself - something
code:

var num : int
put "Enter a number: "..
get num
num -= 2
put "Your number minus 2 is equal to ", num %even though you got num you change it to num := num - 2

You were a little confused when you said
Mr.Programmer wrote:

Ohhh. Then i guess var -= 22 is like saying ' var + var - 22 '?

If so then it makes sense.

And thank you very much.
Clayton




PostPosted: Thu Feb 28, 2008 9:33 pm   Post subject: RE:Kind of Stupid Question (+=,-=)

I very much believe the :+ was a typo.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: