Next: 7.2 Structured statements
Up: 7. Statements
Previous: 7. Statements
Subsections
A simple statement cannot be decomposed in separate statements. There are
basically 4 kinds of simple statements:
Simple statements
Of these statements, the raise statement will be explained in the
chapter on Exceptions (chapter Exceptions)
Assignments give a value to a variable, replacing any previous value the
observable might have had:
Assignments
In addition to the standard Pascal assignment operator ( := ), which
simply replaces the value of the varable with the value resulting from the
expression on the right of the := operator, Free Pascal
supports some c-style constructions. All available constructs are listed in
table (assignments) .
Table:
Allowed C constructs in Free Pascal
Assignment |
Result |
a += b |
Adds b to a, and stores the result in a. |
a -= b |
Substracts b from a, and stores the result in
a. |
a *= b |
Multiplies a with b, and stores the result in
a. |
a /= b |
Divides a through b, and stores the result in
a. |
For these constructs to work, you should specify the -Sc
command-line switch.
Remark: These constructions are just for typing convenience, they
don't generate different code.
Here are some examples of valid assignment statements:
X := X+Y;
X+=Y; { Same as X := X+Y, needs -Sc command line switch}
X/=2; { Same as X := X/2, needs -Sc command line switch}
Done := False;
Weather := Good;
MyPi := 4* Tan(1);
Procedure statements are calls to subroutines. There are
different possibilities for procedure calls: A normal procedure call, an
object method call (qualified or not) , or even a call to a procedural
type variable. All types are present in the following diagram.
Procedure statements
The Free Pascal compiler will look for a procedure with the same name as given in
the procedure statement, and with a declared parameter list that matches the
actual parameter list.
The following are valid procedure statements:
Usage;
WriteLn('Pascal is an easy language !');
Doit();
Free Pascal supports the goto jump statement. Its prototype syntax is
Goto statement
When using goto statements, you must keep the following in mind:
- The jump label must be defined in the same block as the Goto
statement.
- Jumping from outside a loop to the inside of a loop or vice versa can
have strange effects.
- To be able to use the Goto statement, you need to specify the
-Sg compiler switch.
Goto statements are considered bad practice and should be avoided as
much as possible. It is always possible to replace a goto statement by a
construction that doesn't need a goto, although this construction may
not be as clear as a goto statement.
For instance, the following is an allowed goto statement:
label
jumpto;
...
Jumpto :
Statement;
...
Goto jumpto;
...
root
1999-06-10