Ozark has three control-flow constructs:
if
/with
/else
all
repeat
This is an intentionally small set; each allows predictable patterns for accomplishing specific things.
If / With / Else
The if
statement evaluates a Boolean value and, if that value is true
, executes the body.
The if
statement body is executed, or not, based on the result of the conditional. For more complex if
statements that involve pattern matching, the powerful ... notation can be used to match a value or tuple with a value description. The with
keyword unpacks an optional variable. with
is mandatory shorthand for if «someOptional» is not nil
.
Conditions following an else
execute only if none of the previously chained statements have executed.
Conditions can omit trailing any
flags.
inheritance Example method branch object: Object, condition1: Boolean, condition2: Boolean if condition1, condition2 is ... true, 3 object doSomething ... false object doSomethingElse ... else any, in [1, 2, 5] object doAnotherThing ... else object reset
inheritance Example method testAndContinue object: ExampleObject? with object object doSomething print "Success" ... else print "Cannot continue - no object."
All
The all
keyword indicates that an array is being used in place of an object, and that the statement will be executed once for every element in the array.
This can be used with multi-dimensional arrays.
inheritance Example method printRange count: Integer print all [1~count] method printNames attendees: [Attendee] all attendees name -> names print all names
Repeat
The repeat
clause is appended to a statement after a pipe |
. It indicates that the statement should repeat based on the type and parameters of the following clause. Valid repeat
clauses follow one of these formats:
repeat X times
repeat while someCondition
repeat until someCondition
In the above examples, someCondition indicates an output of the statement, and X can represent any Integer or Integer variable.
inheritance Example method listenForInput io: StandardIO io getInputFromUser -> input | repeat until input is not nil method growTo2KB file: implied File @fileManager appendToFile file chunk: 1000 -> size | repeat until size is 2000000