Assignments (see Assignments), Procedure calls (see Procedure Calls),
if statements (see If), while (see While), repeat (see
Repeat) and for loops (see For), and the return statement (see
Return) are called statements. They can be entered interactively or be
part of a function definition. Every statement must be terminated by a
semicolon.
Statements, unlike expressions, have no value. They are executed only to
produce an effect. For example an assignment has the effect of assigning
a value to a variable, a for loop has the effect of executing a
statement sequence for all elements in a list and so on. We will talk
about evaluation of expressions but about execution of statements to
emphasize this difference.
Using expressions as statements is treated as syntax error.
gap> if i <> 0 then k = 16/i; fi;
Syntax error: := expected
if i <> 0 then k = 16/i; fi;
^
gap>
As you can see from the example this warning does in particular address
those users who are used to languages where = instead of := denotes
assignment.
Empty statements are permitted and have no effect.
A sequence of one or more statements is a statement sequence, and may
occur everywhere instead of a single statement. There is nothing like
PASCAL's BEGIN-END, instead each construct is terminated by a keyword.
The simplest statement sequence is a single semicolon, which can be
used as an empty statement sequence. In fact an empty statement
sequence as in for i in [1..2] do od is also permitted and is
silently translated into the sequence containing just a semicolon.
[Top] [Previous] [Up] [Next] [Index]
GAP 4 manual