- Introduction
- Control Structures
- If/Then Selection Structure
- If/Then/Else Selection Structure
- While Repetition Structure
- DoWhile/Loop Repetition Structure
- DoUntil/Loop Repetition Structure
- Do/LoopWhile Repetition Structure
- Do/LoopUntil Repetition Structure
- Assignment Operators
- For/Next Repetition Structure
- Example: Using the For/Next Structure to Compute Compound Interest
- SelectCase Multiple-Selection Structure
- Using the Exit Keyword in a Repetition Structure
- Logical Operators
- Introduction to Windows Application Programming
- Summary
3.10 Assignment Operators
Visual Basic .NET provides several assignment operators for abbreviating assignment statements. For example, the statement
value = value + 3
can be abbreviated with the addition assignment operator (+=) as
value += 3
The += operator adds the value of the right operand to the value of the left operand and stores the result in the left operand's variable. Any statement of the form
variable = variable operator expression
where operator is one of the binary operators +, -, *, ^, &, / or \, can be written in the form
variable operator= expression
Figure 3.2 lists the arithmetic assignment operators and provides sample expressions using these operators and corresponding explanations.
Although the symbols =, +=, -=, *=, /=, \=, ^= and &= are operators, we do not include them in operator-precedence tables. When an assignment statement is evaluated, the expression to the right of the operator always is evaluated first and subsequently assigned to the variable on the left. Unlike Visual Basic's other operators, the assignment operators can occur only once in a statement.
Fig. 3.2 Assignment operators.