Control Flow
Programs often need to choose between actions, repeat work, or recover when an operation fails. Control flow defines those decisions and the order in which statements run. For example, a program can process every invoice but stop when a required value is missing.
Devlish groups statements with indentation. The examples below explain conditions, loops, and error recovery; read Syntax Basics first if comparisons and assignment are new to you.
If / Otherwise
Section titled “If / Otherwise”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"For Each Loop
Section titled “For Each Loop”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 statusIterating over records from a list:
For each invoice in invoices: Print amount of invoiceWhile Loop
Section titled “While Loop”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_countUntil Loop
Section titled “Until Loop”Repeat until a condition becomes true (inverse of While).
status equals "pending"
Until status is "complete": # do work status equals "complete"Continue and Break
Section titled “Continue and Break”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 BreakTry / Otherwise (Error Recovery)
Section titled “Try / Otherwise (Error Recovery)”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 configOtherwise: config equals record with "default" as mode Print last_errorTry blocks catch validation failures, file errors, HTTP errors, and explicit Fail with statements.
Fail With
Section titled “Fail With”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 messageNesting
Section titled “Nesting”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