For the complete documentation index, see llms.txt. This page is also available as Markdown.

Control flow

OSL uses parentheses for statement blocks.

Conditions

if score >= 90 (
  log "A"
) else if score >= 80 (
  log "B"
) else (
  log "C or below"
)

A one-statement guard may stay on one line:

if user == null return {error: "User not found"}
if message == null continue
if complete break

return, continue, and break are the supported inline guard bodies. Use a block for anything else.

Boolean operators

Use and, or, and the ! prefix:

boolean allowed = authenticated and !banned

and and or short-circuit. ?? checks only for null, so it preserves false, 0, and an empty string.

Counted loops

for name count counts from 1 through the evaluated count:

This logs 1, 2, and 3. The compiler evaluates the bound once.

loop count repeats a block without declaring an index:

Collection loops

in yields values. With two names it yields the 1-based position and value:

of yields positions for arrays and strings, or keys for objects:

Use _ when you do not need one side of a two-value loop:

while and until

match

match is an expression. A non-enum match requires an _ arm:

An arm may use a block and return a value:

Use match for new code. switch also exists for command-style fallthrough cases, but it is easier to get wrong because cases continue until break.

Last updated