From 57ad7f1f8261374349af75cc2f48261f790abdd4 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Tue, 5 Jul 2022 13:43:21 -0400 Subject: [SPEC] explain loops better --- spec/1.md | 40 +++++++++++++++++++++++++++++++++++----- 1 file 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 ( ) + /; if ( ) ;/ # if block with else and else if - /; if ( ; ; ... ; ) + /; if ( ; ... ; ) - ;; else if ( ) + ;; else if ( ; ... ; ) ;; else ;/ # loop block - /; loop ( ; ... ; ) - [ ] + /; loop ( ; ... ; ) + [ ; ... ; ] ;/ @@ -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 [ ] + + ;/ + + # Same as a while loop + /; loop ( ) + + ;/ + + # Infinite loop + /; loop + + ;/ + + # Adding statements to mimic a for loop + /; loop (int i = 0; i < 10) [i++] + + ;/ + ## Section 3 - Statements ### TNSL Statement Notation -- cgit v1.2.3