Game Development Reference
In-Depth Information
Table 3-5 . Java Assignment Operators, What Each Assignment Is Equal to in Code, and
a Description of the Operator
Operator Example
Description
=
C=A+B
Basic assignment operator: Assigns value from right-hand oper-
and to left-hand operand
+=
C+=A
equals
C=C+A
ADD assignment operator: Adds right-hand operand to left-hand
operand; puts result in left-hand operand
-=
C-=A
equals
C=C-A
SUB assignment operator: Subtracts right-hand operand from left-
hand operand; puts result in left-hand operand
*=
C*=A
equals
C=C*A
MULT assignment operator: Multiplies right-hand operand and
left-hand operand; puts result in left-hand operand
/=
C/=A
equals
C=C/A
DIV assignment operator: Divides left-hand operand by right-
hand operand; puts result in left-hand operand
%=
C%=A
equals
C=C%A
MOD assignment operator: Divides left-hand operand by right-
hand operand; puts remainder in left-hand operand
Finally, you are going to take a look at conditional operators, which also allow you
to code powerful game logic.
Java Conditional Operators
The Java language also has a conditional operator that can evaluate a condition and
make a variable assignment for you, based on the resolution of that condition, using
only one compact programming construct. The generic Java programming statement
for a conditional operator always uses the following basic format:
Variable = (evaluated expression) ? Set this value if
TRUE : Set this value if FALSE ;
So, on the left-hand side of the equals sign, you have the variable, which is going to
change (be set), based on what is on the right-hand side of the equals sign. This con-
forms to what you have learned thus far.
 
Search WWH ::




Custom Search