CAS 6


Control Structure Examples

For loop

Loop through each number from 0-2. GenerateIndices create an object array starting with index 0.

num←Numeric.New 3
loopIndex←num.GenerateIndices 0
num←Numeric.New 0

:For I :In loopIndex
    _←num.Plus I
:EndFor

Repeat and Until

Loop until equal to a specific value.

Not reaching the value will result in an infintie loop and the script will never end.

I←Numeric.New 0
:Repeat
    I←I.Plus 1
:Until I.Eq 100

Loop until equal to one of two conditions.

Not reaching the any condition will result in an infintie loop and the script will never end.

I←Numeric.New 0
:Repeat
    I←I.Plus 1
:Until I.Eq 100
:OrIf I.Eq 50

If Condition

Simple if. When condition si not met, the whole if block will be bypassed.

I←Numeric.New 0
:If I.Gt 0
    ⍝ Do something..
:EndIf

If, else condition block.

I←Numeric.New 0
:If I.Gt 0
    ⍝ Do something..
:Else
    ⍝ Do something..
:EndIf

If ElseIf, Else condition block.

:If Numeric.New 0
    ⍝ Do something..
:ElseIf Boolean.New 1
    ⍝ Do something..
:EndIf

If, OrIf, Else condition. The first condition will be met if either or is met.

:If Numeric.New 0
:OrIf Boolean.New 1
    ⍝ Do something..
:Else
    ⍝ Do something..
:EndIf

If, AndIf, Else condition. The first condition will only if both If and AndIf results are true.

:If Numeric.New 1
:AndIf Boolean.New 1
    ⍝ Do something..
:Else
    ⍝ Do something..
:EndIf

While loop

Continue execution until While condition is met.

Not reaching the value will result in an infintie loop and the script will never end.

I←Numeric.New 0
:While I.Lt 100
    I←I.Plus 1
:EndWhile

Exit Script

The return statement will immediately exit the script.

:Return

Exit on condition

:If Numeric.New 1
:AndIf Boolean.New 1
    :Return
:EndIf