if, elseif and guards in Julia
Blocks close with end; && and || double as one-line guards.
cloud_pct = 35
# if/elseif/else close with end; the condition takes no parens.
if cloud_pct < 20
println("Full survey night")
elseif cloud_pct < 60
println("Bright targets only")
else
println("Close the dome")
end
# The ternary picks a value; && and || short-circuit as guards.
mode = cloud_pct < 50 ? "imaging" : "standby"
println("Mode: $mode")
cloud_pct < 40 && println("Guider can lock")
How it works
if/elseif/elseneed no parentheses around conditions.- The ternary
? :picks a value for an assignment. cond && println(...)runs the right side only when the left holds.
Keywords and builtins used here
elseelseifendif
The run, in numbers
- Lines
- 15
- Characters to type
- 393
- Tokens
- 63
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 54 seconds.
Step 1 of 3 in Control flow, step 4 of 27 in Language basics.