#About statements and expressions
This page describes declarations, control flow and expressions in LumaScript.
let speed = 12.0 // a constant local
var count = 0 // a variable local
count += 1
if count > 3 { log "many" } else if count == 0 { log "none" }
while count < 10 { count += 1 }
for i in 0..10 { } // ranges
for item in items { } // lists, sets: the values; maps: (key, value) pairs
for (i, item) in items.indexed { }
match shape {
Shape.Circle(r) => area = 3.14159 * r * r
Shape.Box { w, h } => area = w * h
else => area = 0.0
}
defer log "left" // runs when the block ends, however it ends
return valuematchmust cover every case or haveelse; a missing case is a compile error naming it.guard <condition or let> else { ... }: theelseblock must leave the function, task or loop (return,stop,break,continue); after it, names bound byguard letare in scope.guard let a = x, let b = y, a > 0 elsechecks each in order.ifandmatchare expressions when every branch gives a value:let s = if big { 2.0 } else { 1.0 }.