Perl Control Structures - Statement Modifiers

Statement Modifiers

Perl also provides variants of the loop and conditional constructs that work on a simple statement (an expression evaluated for its side-effects) instead of a block:

statement if expr; statement unless expr; statement while expr; statement until expr; statement foreach list;

The while and until modifiers test the controlling expression before executing the statement, just like their loop counterparts. However, they are not considered actual loops, so the loop control keywords next, last and redo cannot be used with them. They have special semantics when combined with the do keyword:

do block while expr; do block until expr;

In these constructs, the condition is tested after the block is executed, so the block always executes at least once.

These modifiers cannot be nested, so the following is illegal

statement if expression for list; #ERROR

and should be written as one of:

( expression ) and ( statement ) for list; for ( list ) { statement if expression } do { statement if expression } foreach list;

Read more about this topic:  Perl Control Structures

Famous quotes containing the word statement:

    Truth is that concordance of an abstract statement with the ideal limit towards which endless investigation would tend to bring scientific belief, which concordance the abstract statement may possess by virtue of the confession of its inaccuracy and one-sidedness, and this confession is an essential ingredient of truth.
    Charles Sanders Peirce (1839–1914)