Chapter 7. Statements

7.1 General

A statement describes an action performed during program execution.

Statements control the flow of execution, modify program state, invoke routines, and introduce local declarations.

A Buoy program executes by evaluating statements in the order determined by the language’s control-flow rules.


7.2 Statement Categories

The language defines the following categories of statements:

  • declaration statements
  • assignment statements
  • Sub invocation statements
  • conditional statements
  • iteration statements
  • jump statements
  • block statements
  • exception handling statements
  • compiler directive statements

Additional statement forms may be introduced by future revisions of the language.


7.3 Blocks

A block is a sequence of zero or more statements treated as a single syntactic unit.

Blocks establish a new lexical scope.

Names declared within a block are visible only within that block and any nested blocks unless otherwise specified.

Execution proceeds sequentially from the first statement of the block to the last unless altered by a control-flow statement.


7.4 Empty Statements

An empty statement performs no action.

An implementation may permit empty statements where the grammar requires a statement but no operation is desired.

Empty statements have no observable effect.


7.5 Assignment Statements

An assignment statement evaluates an expression and stores the resulting value into a variable, property, or other assignable storage location.

The destination shall be writable and the assigned value shall be compatible with the destination type.

The assignment completes only after the right-hand expression has been fully evaluated.


7.6 Sub Invocation Statements

Invoking a Sub performs an action.

Because a Sub does not return a value, its invocation forms a statement rather than an expression.

Examples include:

  • writing output
  • modifying application state
  • updating a collection
  • performing file operations

Execution resumes with the statement immediately following the invocation once the Sub completes.


7.7 Conditional Statements

Conditional statements execute one of several alternative statement sequences depending upon the value of a Boolean expression.

The language provides conditional constructs including:

  • If
  • Select
  • other conditional forms defined by the grammar

Only one alternative is executed for each evaluation of the conditional construct.


7.8 Iteration Statements

Iteration statements repeatedly execute a statement or block.

The language provides several iteration constructs appropriate for different programming tasks.

Typical forms include:

  • counted iteration
  • conditional iteration
  • collection iteration

Each iteration construct specifies the conditions under which execution begins, continues, and terminates.


7.9 Jump Statements

Jump statements alter the normal sequential flow of execution.

Examples include:

  • Return
  • Exit
  • Continue
  • Break

Each jump statement transfers control to a well-defined destination determined by the enclosing construct.

Jump statements shall not transfer control into a nested scope.


7.10 Return

A Return statement terminates execution of the current Function or Sub.

Within a Function, Return specifies the value produced by the invocation.

Within a Sub, Return transfers control to the caller without producing a value.

A Function shall not complete execution without returning a value compatible with its declared return type.


7.11 Statement Execution

Unless otherwise specified, statements execute in source order.

Each statement completes before execution begins for the following statement.

The language defines additional ordering guarantees for expressions and routine invocations where necessary.


7.12 Reachability

The compiler performs control-flow analysis to determine whether a statement is reachable.

Statements that cannot be executed are considered unreachable.

A conforming implementation may diagnose unreachable statements during compilation.


7.13 Summary

Statements describe the executable behaviour of a Buoy program.

Expressions compute values.

Statements use those values to perform work, direct control flow, and modify program state.