Initial Values¶
Variables can be assigned initial values in their declaration using the
:= operator.
IEC 61131-3 |
Section 2.4.3 |
Support |
Supported |
Syntax¶
variable_name : type_name := initial_value ;
The initial value must be a constant expression compatible with the variable’s type.
Example¶
PROGRAM main
VAR
counter : INT := 0;
active : BOOL := TRUE;
scale : REAL := 1.5;
END_VAR
counter := counter + 1;
END_PROGRAM
If no initial value is specified, the variable is initialized to the default value of its type (typically zero or empty).
See Also¶
Variable Declarations — variable declaration syntax
Data Types — default values for each type