aboutsummaryrefslogtreecommitdiff
path: root/language/statements/structure.rst
blob: 9330bf6a37e9220956b0cf545683537717f2f99b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Structure Statements
^^^^^^^^^^^^^^^^^^^^

.. crowbar:element:: StructureStatement <- IfStatement / SwitchStatement / WhileStatement / DoWhileStatement / ForStatement

    A structure statement creates some nonlinear control structure.
    There are several types of these structures.

.. crowbar:element:: IfStatement <- 'if' '(' Expression ')' Block ('else' Block)?

    An if statement allows some action to be performed only sometimes, based on the value of the expression.

    Compile-time Behavior:

    If the expression does not have type bool, the compiler must emit an error.

    Runtime Behavior:

    First, the expression is evaluated.
    If the expression evaluates to a ``bool`` value of ``true``, then the first block will be executed.
    If the expression evaluates to a ``bool`` value of ``false``, either the second block is executed or nothing is executed.