Skip to content

Flow control

Daniel Gu edited this page Mar 28, 2023 · 1 revision

NOTE: Indents are not necessary, but are strongly encouraged to improve readability.

Selection

If statements

IF expr THEN
    ...
ENDIF

Else if and else blocks are not supported yet.

Iteration

Conditional

There are 2 conditional loop structures in CambridgeScript:

Pre-conditional

WHILE expr DO
    ...
ENDWHILE

Post-conditional

REPEAT
    ...
UNTIL expr

Count-controlled

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 type INTEGER)
  • The range is inclusive on both ends (FOR x <- 1 TO 5 will set x 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

Clone this wiki locally