Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Input & Output

Output

StatementDescription
print <value>Print a value without a trailing newline
println <value>Print a value followed by a newline
print 'Loading...'
println 'done'

Input

Input statements write into an existing variable, referenced with a leading &:

StatementDescription
inputInt &varRead a line from stdin, parse it as an integer, store it in var
inputStr &varRead a whitespace-delimited token from stdin, store it in var
age = 0
print 'Enter your age: '
inputInt &age
println age
name = ''
print 'Enter your name: '
inputStr &name
println name

Every example in this book assigns a placeholder value (age = 0, name = '') before reading into a variable with inputInt/inputStr. This isn’t strictly required by the compiler — a variable is registered the first time it’s seen, wherever that is — but it’s good practice: it documents the variable’s intended type up front and avoids relying on whatever default the VM gives an unseen variable.

If inputInt receives text that can’t be parsed as an integer, it prints Invalid value! and leaves the variable at 0.