summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-07-05 13:43:21 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-07-05 13:43:21 -0400
commit57ad7f1f8261374349af75cc2f48261f790abdd4 (patch)
treec9fabf638c4a45d36dc6daf091465b7f4ebb6695
parentafb6cd3f8b77d3102f1252cf93e023a94169dace (diff)
[SPEC] explain loops better
-rw-r--r--spec/1.md40
1 files changed, 35 insertions, 5 deletions
diff --git a/spec/1.md b/spec/1.md
index 493bace..7be469c 100644
--- a/spec/1.md
+++ b/spec/1.md
@@ -131,22 +131,22 @@ For if, else, loop, and match any inputs and/or outputs are a semicolon-separate
Examples:
# simple if block
- /; if ( <statement resolving in boolean value> )
+ /; if ( <conditional> )
<statements>
;/
# if block with else and else if
- /; if ( <statement (optional)> ; <statement (optional)> ; ... ; <statement resolving in boolean value> )
+ /; if ( <statements (optional)> ; ... ; <conditional> )
<statements>
- ;; else if ( <statement resolving in boolean value> )
+ ;; else if ( <statements (optional)> ; ... ; <conditional> )
<statements>
;; else
<statements>
;/
# loop block
- /; loop ( <statement (optional)> ; ... ; <statement resolving in boolean value (optional)> )
- [ <statements to be evaluated on loop (optional)> ]
+ /; loop ( <statements (optional)> ; ... ; <conditional (optional)> )
+ [ <statements (optional)> ; ... ; <conditional (optional)> ]
<statements>
;/
@@ -164,6 +164,36 @@ Examples:
;/
;/
+### Loops
+
+The `loop` block can be configured (based on weather or not each boolean statement is omitted) to act as any type of loop.
+
+The *first* conditional is the **initial run condition**. It decides weather the loop is entered at all. If omitted, defaults to `true`, creating a `do ... while` type block.
+
+The *second* conditional is the **subsequent run condition**. It decides weather the loop continues to loop or not. If omitted, it *mirrors* the **initial run condition** (this is equivalent to a `for` or `while` block).
+
+Examples:
+
+ # Same as a do ... while block
+ /; loop [ <conditional> ]
+ <statements>
+ ;/
+
+ # Same as a while loop
+ /; loop ( <conditional> )
+ <statements>
+ ;/
+
+ # Infinite loop
+ /; loop
+ <statements>
+ ;/
+
+ # Adding statements to mimic a for loop
+ /; loop (int i = 0; i < 10) [i++]
+ <statements>
+ ;/
+
## Section 3 - Statements
### TNSL Statement Notation