Decisions with if
An if statement chooses whether a block of code should run:
if temperature > 30 then print("It is hot")endThe condition between if and then must have type Boolean. Pop does not treat numbers, strings, objects, or nil as truthy or falsy values.
Choosing between two paths
Section titled “Choosing between two paths”Add else when the program should run another block if the condition is false:
if score > 9 then print("New high score")else print("Keep trying")endExactly one branch runs. Both finish at the shared end.
Testing several cases
Section titled “Testing several cases”Use elseif to test more conditions without extra nesting:
if score > 89 then print("Excellent")elseif score > 59 then print("Passed")else print("Try again")endConditions are checked from top to bottom, stop after the first true condition, and share one final end. Each branch has its own scope.
See Elseif chains for evaluation order, scopes, and a complete classification example.
Choosing a value
Section titled “Choosing a value”An if expression selects between two values:
local label = if score > 59 then "passed" else "try again"It requires else, has no trailing end, and evaluates exactly one branch. Both branch values must have the same static type. Pop does not use ?: punctuation or invent a union for unlike branches.
Names declared in branches
Section titled “Names declared in branches”Each branch is a scope. A local declared inside it is available only until that branch ends:
if authenticated then local message = "Welcome back" print(message)end
-- message is no longer in scopeWhen the branches only choose one value, prefer an if expression. Use a statement when branches perform several operations or return early.
