Moving forward in chapter 2.
The chapter goes into Data types and numeric operators, as well as numeric literals and shorthand operators.
From what i have read from the web unlike java there are two different numeric data types in Ruby, Integer and Float.
The remainder operator works differently in Ruby as well.
the statement -7%5 = 2 and not -1 like in Java.
7%-5 will however return -2
In Ruby the statement returns the same sign as the second operand.
Shorthand operators are very similar as well with a few differences.
It is important to note that you cant increment variables like in Java.
For example i++ or j-- etc.
You have to use += or -=
Here is a list of Ruby shorthand operators:
For example i++ or j-- etc.
You have to use += or -=
Here is a list of Ruby shorthand operators:
x = 1 this is basically a literal that assigns a variable of 1 to x
x += x this increments by one (because x is one)
x -= x this decrements by one (because x is one)
x += anynumber this increments by whatever number
x *= x this multiplies by x
x **= x raises to the power of
x /= x divides by
No comments:
Post a Comment