0

Shorthand Assignment Operators

In the Ruby tutorial it says "All of the arithmetic operators have corresponding shorthand forms for assignment. For example, a = a + 8 can be written as a += 8. The same applies to the other operators:" Im stumped, how can a = a + 8? Thats like saying 4 = 4 + 1 like that makes no sense and they dont explain it at all

29th Aug 2019, 2:20 AM
Max Rich
Max Rich - avatar
2 Antworten
0
Max Rich I am not into Ruby but this concept is common for c++ also.... in fact in layman terms, you can say that a = a +8 is allowed and 4= 4 + 1 is not allowed.... why because 4 is r value and a is lvalue.... a = a + 8 is not like 4 = 4+1.... a = a + 8 means the way of saying below: a is variable which stores or holds some value... this value should be now incremented by 8... this is what it interprets... in other words, a = 15 for example makes a = 23 post a += 8
29th Aug 2019, 3:56 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
so how would u write that out in code? the 15 example
29th Aug 2019, 3:59 AM
Max Rich
Max Rich - avatar