Skip to content

Control Flow

Devlish uses indented blocks for control flow. Each block must be indented under its parent statement.

Branch execution based on a condition. The Otherwise block runs when the condition is false.

If score > 70:
Print "passed"
Set status to "approved"
Otherwise:
Print "failed"
Set status to "rejected"

Conditions support comparisons and boolean operators:

If status equals "active" and balance > 0:
Print "eligible"

Iterate over a list. The loop variable is available inside the block.

statuses equals list of "pending", "active", and "closed"
For each status in statuses:
Print status

Iterating over records from a list:

For each invoice in invoices:
Print amount of invoice

Repeat while a condition is true.

retry_count equals 0
While retry_count is less than 3:
retry_count equals retry_count plus 1
Print retry_count

Repeat until a condition becomes true (inverse of While).

status equals "pending"
Until status is "complete":
# do work
status equals "complete"

Continue skips to the next iteration. Break exits the loop entirely.

For each item in items:
If status of item equals "skip":
Continue
If priority of item equals "urgent":
Print item
Break

Wrap risky operations in Try. If an error occurs, execution jumps to Otherwise and the error is stored in last_error.

Try:
Read JSON from "config.json" as config
Otherwise:
config equals record with "default" as mode
Print last_error

Try blocks catch validation failures, file errors, HTTP errors, and explicit Fail with statements.

Stop execution with an error message.

Fail with "Contact email is required"

When combined with Require:

Require review_status is "approved" otherwise fail with "Review must be approved"

If Fail with receives a record, it serializes as structured JSON:

Fail with record with "missing_field" as code and "Email required" as message

Control flow blocks can nest freely:

For each project in projects:
If status of project equals "active":
Try:
amount equals value of project
amount must be at least 10000
Otherwise:
Print "Validation failed for project"
Continue