Nested conditions
Conditions inside conditions, and how the period keeps them unambiguous.
Period Block Ending
A period can explicitly finish a block:
Otter
age is 20
if age is at least 18
say "You are an adult."
.
This becomes useful when code gets more complicated.
Both forms are valid:
Otter
score is 120
if score is greater than 100
say "High score!"
say "Finished."
and:
Otter
score is 120
if score is greater than 100
say "High score!"
.
say "Finished."
The period has one structural meaning outside quoted strings:
Finish the current block or process.
It is never used for accessing properties.
Nested Conditions
Indentation makes the relationship clear:
Otter
loggedIn is true
admin is true
if loggedIn
say "Welcome!"
if admin
say "Administrator controls enabled."
say "Login successful."
say "Program finished."
The indentation tells Otter exactly which statements belong to which condition.
The same program with explicit periods:
Otter
loggedIn is true
admin is true
if loggedIn
say "Welcome!"
if admin
say "Administrator controls enabled."
.
say "Login successful."
.
say "Program finished."