Assignments and Comparisons

When you put a value into a variable, you are assigning that value to the variable, and you use an assignment operator to do the job. For example, you use the equals operator to make an assignment, such as hisName = "Tom". There are a whole set of assignment operators as listed in Table 1.4.

Table 1.4. Assignments
AssignmentWhat it does
x = ySets x to the value of y
x += ySame as x = x + y
x -= ySame as x = x - y
x *= ySame as x = x * y
x /= ySame as x = x / y
x %= ySame as x = x % y

Other than the equals sign, the other assignment operators serve as shortcuts for modifying the value of variables. For example, a shorter way to say x=x+5 is to say x+=5. For the most part, we’ve used the longer version in this book for clarity’s sake.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.119.97