Control flow
let score = 85
if score >= 90 print "A"else if score >= 80 print "B"else print "C"A condition must be a bool. There is no truthiness, so if count is an error: write if count > 0.
then expressions
Section titled “then expressions”if ... then ... else is an expression, for choosing a value:
let n = 3let label = if n == 1 then "item" else "items"print "{n} {label}"var count = 0while count < 3 count += 1print countfor visits a range, a text’s characters, a list’s elements, a set’s values, or a map’s keys.
for i in 0..3 # 0, 1, 2 print i
for i in 0..=3 # 0, 1, 2, 3 print i
for name in ["Ada", "Linus"] print nameA range reads its bounds once, and the loop name cannot be assigned. The body of a for can read what it visits, but cannot change it. To change each element of a list, use for change, see Collections.
break and continue
Section titled “break and continue”for i in 0..10 if i % 2 == 0 continue if i > 7 break print iand, or, and not work on bool. and and or skip their right side when the left side decides the result. Comparisons do not chain: a < b < c is an error.
let age = 20let member = trueif age >= 18 and not member print "guest"else if age >= 18 and member print "member"Matching on values is covered in Types, choices, and unions.