• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Modifying Variables

Variables are useful because you can always change their contents with updated information about the status of the movie or your viewer. Sometimes, this change involves assigning a new value to the variable. At other times, the change means adding, subtracting, multiplying, or dividing the variable’s numeric values or modifying a string by adding characters. The variable myScore, for example, could be initialized at 0. Then, for every goal a player makes, the myScore variable changes in increments of 1. The job of modifying information contained in variables falls upon operators —symbols that “operate” on data.

Assignment and arithmetic operators

The assignment operator (=) is a single equals sign that assigns a value to a variable. You’ve already used this operator in initializing variables and creating new objects. Table 9.3 lists the other common operators.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint