= Statement

The direct assignment statement assigns a value to a variable.

Format

var = expr

var += expr

var -= expr

var *= expr

var /= expr

var := expr

Parameter(s)

var

Variable to be assigned.

expr

An expression evaluating to the value to be assigned to var.

Description

The direct assignment statement (=) assigns the value of expr to the variable var. In addition, there are several other forms of the assignment statement, of the form var op= expr, which is equivalent to var = var op expr.

= expr

var takes the current value of expr.

+= expr

var becomes var plus the current value of expr.

-= expr

var becomes var minus the current value of expr.

*= expr

var becomes var multiplied by the current value of expr.

/= expr

var becomes var divided by the current value of expr.

:= expr

var becomes var concatenated with the current value of expr.

Examples

If the SURNAME were to be appended to the variable NAME, the code might read:

NAME : = SURNAME

In the next application, assignment statements are used to assign to the variable PROFIT the value of COST minus PRICE, and then to subtract from PROFIT the value of the overhead allotted to that sale. An external subroutine CALC.OVERHEAD assigns the value OVERHEAD based on the value of PROFIT.

PRINT "ENTER COST OF ITEM: "

INPUT COST

PRINT "ENTER PRICE AT WHICH ITEM WAS SOLD: "

INPUT PRICE

PROFIT = COST - PRICE

CALL CALC.OVERHEAD (PROFIT,OVERHEAD)

PROFIT  - =  OVERHEAD

PRINT "WITH OVERHEAD TAKEN INTO ACCOUNT, THE

PROFIT IS:"

PRINT PROFIT

See Also

Statement and Function Reference