Historical ControlFlow, Revision 2

Control Flow Statements

Like all procedural programming languages, Euphoria has a set of statements that control the execution flow of the program.

IF

This would probably be the most common form of flow control statement. It works by testing if some expression is true or false, then depending on the result runs one set of statements or another set of statements.

Syntax

The general format is ...

if BOOLEXPR then
    TRUESTMT
else 
    FALSESTMT 
end if

Where BOOLEXPR is any expression that evaluates to a single number; zero is deemed to be false and non-zero is deemed to be true. If the expression is non-zero (true) then all the statements in TRUESTMT are run then control goes to the first statement after the end if clause. However, if the expression evaluates to zero (false) then all the statements in FALSESTMT are run then control goes to the first statement after the end if clause.

There are a couple of variations to the general syntax. The first one is the elsif clause.

if BOOLEXPR1 then
    TRUESTMT1 
elsif BOOLEXPR2 then 
    TRUESTMT2

elsif BOOLEXPR3 then 
    TRUESTMT3
. . .
else
    FALSESTMT 
end if

This is almost the same as before however, if BOOLEXPR1 is false then BOOLEXPR2 is tested, and so on in order. As soon as one expression is true, the statements in the corresponding if or elsif clause are run, then control proceeds to after the end if. If all expressions are false, then the statements in the else clause are run.

SWITCH

FOR

WHILE

LOOP

GOTO

Routine Calls

Expressions

Search



Quick Links

User menu

Not signed in.

Misc Menu