Statements
CHAPTER 5: STATEMENTS
Expression
- Any construction that can be used where a value is required
- Typically composed of literals, variables, operators, functions
and subroutine calls
- Only two types of expressions: scalar and list
Statement
- Simple
- Compound
Simple Statement
- Expression optionally followed by a modifier
- Terminated with a semicolon
Compound Statement
- Statement built out of expressions and statement blocks
Statement Block
- Sequence of statements enclosed in matching curly braces, {}
- Accepted anywhere a simple statement is allowed
Simple Statements
- EXPR
- EXPR_1 if EXPR_2
- EXPR_1 unless EXPR_2
- EXPR_1 while EXPR_2
- EXPR_1 until EXPR_2
- EXPR_1 ? EXPR_2 : EXPR_3
- EXPR_1 && EXPR_2
- EXPR_1 || EXPR_2
- do BLOCK [while EXPR]
- do BLOCK [until EXPR]
- Note that the last two are considered simple statements even
though they contain statement blocks
Compound Statements
- if (EXPR_1) BLOCK [ [ elsif (EXPR_2) BLOCK...] else BLOCK ]
- unless (EXPR_1) BLOCK [ else BLOCK ]
- [LABEL:] while (EXPR) BLOCK [ continue BLOCK ]
- [LABEL:] until (EXPR) BLOCK [ continue BLOCK ]
- [LABEL:] for (EXPR_1; EXPR_2; EXPR_3) BLOCK
- [LABEL:] foreach VAR (ARRAY) BLOCK
- [LABEL:] BLOCK [ continue BLOCK ]
Bob Tarr
University of Maryland, Baltimore County
tarr@umbc.edu