Control Flow
Branches
Use if, optional elif branches, and an optional else. Every body needs braces.
input endpoint: url
response = http.get(endpoint, timeout=3s)
if response.status == 200 {
print("up")
} elif response.status >= 500 {
print("server error")
} else {
print("unexpected status")
} Iteration
Use for to iterate over a list or set. Do not depend on iteration completion or output order.
for port in [80, 443, 8080] {
print(port)
} For explicit concurrent work, use parallel for. max is optional; when supplied, it limits concurrency alongside the run’s own limits.
input endpoints: list<url>
parallel(max=4) for endpoint in endpoints {
response = http.get(endpoint, timeout=3s)
out(response.status)
} parallel for endpoint in endpoints { ... } is also valid. Keep iterations independent. break stops a loop and continue skips the rest of an iteration; both work in ordinary for, while, and repeat loops, but not in parallel for.
Repeating work
while checks its condition before each iteration. repeat runs the body before testing until; it requires max and accepts an optional every delay.
attempts = 0
repeat(max=3, every=1s) until attempts >= 2 {
attempts = attempts + 1
print(attempts)
} Use a bound or a clear exit condition. Run limits can stop work even if your loop condition remains true.
List comprehensions
Build and optionally filter a list in one expression:
values = [1, 2, 3, 4]
evens = [n * 2 for n in values if n % 2 == 0]
out(evens) Use try/catch inside a loop when one failed operation should not stop the remaining work.