Statements
A simple statement is an expression evaluated for its side effects. Every simple statement must end in a semicolon, unless it is the final statement in a block.
A sequence of statements that defines a scope is called a block.
Generally, a block is delimited by braces, or { }.
Compound statements are built out of expressions and blocks.
A conditional expression is evaluated
to determine whether a statement block will be executed.
Compound statements are defined in terms of
blocks, not statements, which means that
braces are required.
Any block can be given a label.
Labels are identifiers that follow the variable-naming rules (i.e.,
they begin with a letter or underscore, and can contain alphanumerics and
underscores).
They are placed just before the block and are followed by a colon,
like SOMELABEL here:
SOMELABEL: {
...statements...
}
By convention, labels are all uppercase, so as not to conflict with
reserved words. Labels are used with the loop-control
commands next, last, and redo to alter
the flow of execution
in your programs.
Conditionals and Loops
The if and unless statements execute blocks of code depending
on whether a condition is met. These statements take the following forms:
if (expression) {block} else {block} unless (expression) {block} else {block} if (expression1) {block} elsif (expression2) {block} ... elsif (lastexpression) {block} else {block}
while loops
The while statement repeatedly executes a block as long as its conditional expression is ...