Assignments (see Assignments), Procedure calls (see Procedure Calls),
if statements (see If),
while (see While),
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
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.
It is possible to use expressions as statements. However this does cause a warning.
gap> if i <> 0 then k = 16/i; fi; Syntax error: warning, this statement has no effect if i <> 0 then k = 16/i; fi; ^
As you can see from the example this is useful for those users who are
used to languages where
= instead of
:= denotes assignment.
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 most simple statement sequence is a single semicolon, which can be used as an empty statement sequence.
Previous Up Top Next