This is probably a very trivial question, but..
Assuming we have a variable ‘a’ that has a value of 10
Then we have a variable ‘b’ that has a value of 5
Can I remove the value of ‘b’ from ‘a’ (leaving 5) and change the value of a each time?
In my head I think of it as:
a - b = 5
a - b = 0
a - b = -5
etc etc..
Thanks!
Consider this:
Now the value of
ais5. This is because Ruby evaluates what is on the right side of the assignment operator=first and then assigns that value to whatever is on the left side.There is also a shortcut since this type of math is very common
If you want to do this a certain number of times, try a loop.
For further basic Ruby learning, I would suggest Try Ruby to get you started on concepts as I mentioned above. (Type “next” there to get started)