Statements
A statement is a full instruction. It can contain keywords, operators, variables, constants, and expressions. Each statement goes into one of the categories that follow:
- Declaration statements give names to variables, constants, and procedures. They can also supply a data type.
- Control statements cause something to occur. They can call a procedure, or move control through loops and branches in code. They can also change a variable with an assignment statement.
Declaration statements
You use declaration statements to identify and make procedures, variables, constants, and more. When you declare a programming construct, you can also identify its data type, access level, and scope. See Declared Element Qualities for more information,.
Initial values
TODO
Control statements
A control statement causes changes. It can move to different parts of the code, run other statements again and again, or calculate a result.
Assignment statements
An assignment statement is a special type of control statement.
It gets the value on the right side of the assignment operator (=
), then stores that in the element on the left side.
An example follows.
x = 42
Here the assignment statement stores the literal value 42 in the variable x.
L-values and r-values
TODO
Data types and conversions
TODO
Compound assignment
A compound assignment statement first does an operation on an expression, then assigns the result to a variable.
The example below uses the operator +=
.
It adds the value of the expression on the right to the value of the variable on the left.
x += 1
This is the same as the statement that follows.
x = x + 1
For a list of such operators, see Assignment Operators.
Chained assignment
You can give many variables the same value with one statement.
Chained assignment uses a special operator (:=
).
You put this operator after each of the variables, then put an expression last.
You cannot use other assignment operators with this statement.
An example follows.
' Reset the coordinates.
x := y := z := 0.0
Note: You also can use the operator :=
in arguments passed to procedures.
See Parameter List for more information.
Putting many statements on one line
You can write two or more statements on one line.
You put the semicolon symbol (;
) between each one-line statement.
An example follows:
total += subtotal(row) ; Print total
Each statement in a line must be a one-line statement.
Compound statements, which include loops and procedures, are not applicable.
And compound statements with a one-line construct (If…Else
and New
) are also not applicable.
For a list of the one-line statements, see If…Else Statement § One-line construct.
Note: This syntax can make code that is not easy to read, which can cause increased maintenance time. Thus, we recommend that you keep lines to one statement each.
Dividing one statement into many lines
Most statements are short, but can become too long to read easily.
You can divide a long statement into two or more lines of code.
You write a space and an underscore (_
) before the end-of-line.
In the example that follows, a name and address returned from a database table are printed to a label.
#address_label.Text = _
#row!Name & $N & _
#row!Address
Divided statements without the underscore
Some conditions let you continue a statement on a different line without the underscore character (_
).
In the table that follows are the elements of a statement and conditions in which the compiler ignores an end-of-line.
Element | Example |
---|---|
After a comma (, ) |
|
After a left parenthesis (( ) |
|
After a left brace ({ ) or between two right braces (} ) |
|
After an assignment operator
(= , := ,
*= , /= , Div= , Mod= , Rem= ,
+= , -= ,
And= , Or= , Xor= ,
SHL= , SHR= ,
&= ) |
|
After a modifier that starts with the at-sign (@ ) |
|
For information about using comments after a line continuation sequence, see the section below.
Adding comments
TODO
comments and divided statements
TODO