aboutsummaryrefslogtreecommitdiff
path: root/language
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-11-02 22:51:55 -0700
committerMelody Horn <melody@boringcactus.com>2020-11-02 22:51:55 -0700
commitc7f8dc29ea3b4307d35d1f38596ba970af9318fd (patch)
tree8612b63dd54907d3a17cf05890dcd253ec8f7722 /language
parente59e69118302b6a8a9d8c09ed2d5032d432ad33a (diff)
downloadspec-c7f8dc29ea3b4307d35d1f38596ba970af9318fd.tar.gz
spec-c7f8dc29ea3b4307d35d1f38596ba970af9318fd.zip
add flow control statements
Diffstat (limited to 'language')
-rw-r--r--language/statements/flow-control.rst38
-rw-r--r--language/statements/index.rst1
2 files changed, 39 insertions, 0 deletions
diff --git a/language/statements/flow-control.rst b/language/statements/flow-control.rst
new file mode 100644
index 0000000..9b21338
--- /dev/null
+++ b/language/statements/flow-control.rst
@@ -0,0 +1,38 @@
+Flow Control Statements
+^^^^^^^^^^^^^^^^^^^^^^^
+
+.. crowbar:element:: FlowControlStatement <- ContinueStatement / BreakStatement / ReturnStatement
+
+.. crowbar:element:: ContinueStatement <- 'continue' ';'
+
+ Compile-time Behavior:
+
+ Only valid inside a :crowbar:ref:`WhileStatement`, :crowbar:ref:`DoWhileStatement`, or :crowbar:ref:`ForStatement` block.
+
+ Runtime Behavior:
+
+ When a continue statement is executed, the innermost loop statement (while, do-while, or for) that contains the continue statement skips the remainder of the execution of its block.
+ For a while or do-while loop, this means skipping to the condition.
+ For a for loop, this means skipping to the update assignments.
+
+.. crowbar:element:: BreakStatement <- 'break' ';'
+
+ Compile-time Behavior:
+
+ Only valid inside a :crowbar:ref:`WhileStatement`, :crowbar:ref:`DoWhileStatement`, or :crowbar:ref:`ForStatement` block.
+
+ Runtime Behavior:
+
+ When a break statement is executed, the innermost loop statement (while, do-while, or for) that contains the break statement ends entirely, skipping any remaining statements, condition tests, or updates.
+
+.. crowbar:element:: ReturnStatement <- 'return' Expression? ';'
+
+ Compile-time Behavior:
+
+ The expression provided must have a type matching the return type of the containing function.
+ If the function has a return type of ``void``, the expression must be omitted.
+
+ Runtime Behavior:
+
+ When a return statement with an expression is executed, the expression is evaluated, and the containing function returns with the value obtained from this evaluation.
+ When a return statement with no expression is executed, the containing function returns.
diff --git a/language/statements/index.rst b/language/statements/index.rst
index e0a0a37..696c059 100644
--- a/language/statements/index.rst
+++ b/language/statements/index.rst
@@ -21,3 +21,4 @@ Statements
variables
structure
+ flow-control