Skip to content

Control Flow

Andrew Johnson edited this page Jun 10, 2025 · 7 revisions

LSTS offers a standard assortment of control flow operators.

If Expressions

Ternary if can be used in expression position.

print(if condition then "true" else "false")

Match Expressions

Match expressions permit destructuring of data in a controlled intentional manner.

match xyz {
   XY { x-field: X { i } } => print(i);
   XYZ { z-field: Z { i } } => print(i);
}

match can destructure lots of things, such as strings or lists.

match "abc" {
   "a".. _ => print("starts with A");
   r/^a+/.. _ => print("starts with at least one A")
};

match [1,2,3] {
   [1.. 2.. _] => print("starts with 1, 2, ...");
};

While Loops

While loops are a common feature available in most languages.

while x < 2 { x += 1; }

For Iteration

For loops allow the programmer to traverse through iterable data.

for x in [1,2,3] { print(x); }

Sequenced Expressions

Expressions and statements can be evaluated sequentially with the semicolon syntax.

print("hello"); 5

//prints hello, then evaluates to 5

Ascription

Manually adding types is not strictly necessary, but can be useful for debugging.

t : T
Clone this wiki locally