-
Notifications
You must be signed in to change notification settings - Fork 3
Flow control
Daniel Gu edited this page Mar 28, 2023
·
1 revision
NOTE: Indents are not necessary, but are strongly encouraged to improve readability.
IF expr THEN
...
ENDIF
Else if and else blocks are not supported yet.
There are 2 conditional loop structures in CambridgeScript:
WHILE expr DO
...
ENDWHILE
REPEAT
...
UNTIL expr
A count-controlled loop can be defined like so:
FOR x <- 1 TO 10 DO
...
NEXT x
A few notes about count-controlled loops:
- You do not need to declare
x
, it will be declared automatically (as typeINTEGER
) - The range is inclusive on both ends (
FOR x <- 1 TO 5
will setx
to 1, 2, 3, 4 and 5 over 5 loop iterations). - You cannot 'skip' iterations by changing the loop variable yourself (you cannot change the value of the variable in the next loop iteration in any way)
For the 2 other people who are going to care aobut this: cambridgeScript grammar