xHarbour Reference Documentation > Operator Reference |
Simple assignment operator (binary): assigns a value to a variable.
<Variable> = <Expression>
The = operator assigns the value of <Expression> to a variable. The recommended assignment operator, however, is the inline assignment operator (:=) which allows for initializing a variable within a variable declaration statement. This is not possible with the simple assignment operator. In addition, the simple assignment operator is interpreted as comparison operator within expressions. This can lead to subtle programming errors since the meaning of the simple assignment operator changes with the context it is used in.
If the variable does not exist when the assignment operation is processed, a PRIVATE variable is automatically created and gets assigned the value of <Expression>.
See also: | ++, --, :=, = (compound assignment) |
Category: | Assignment operators , Operators |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates the use of the assignment operator // and outlines the difference between simple and inline assignment. PROCEDURE Main LOCAL nMonth nMonth = 9 // simple assignment ? nMonth = 9 // result: .T. IF (nMonth := 10) > 0 // inline assignment ? "October" // output: October ENDIF IF (nMonth = 9) > 0 // runtime error ? "September" // (nMonth = 9) -> .F. ENDIF RETURN
http://www.xHarbour.com