If

Syntax

if <test1: test> <block1: block>

elsif <test2: test> <block2: block>

else <block3: block>

Description

There are three pieces to if: "if", "elsif", and "else". Each is actually a separate command in terms of the grammar. However, an elsif must only follow an if, and an else must follow only either an if or an elsif. An error occurs if these conditions are not met.

The semantics are similar to those of any of the many other programming languages these control commands appear in. When the interpreter sees an "if", it evaluates the test associated with it. If the test is true, it executes the block associated with it.

If the test of the "if" is false, it evaluates the test of the first "elsif" (if any). If the test of "elsif" is true, it runs the elsif's block. An elsif may be followed by an elsif, in which case, the interpreter repeats this process until it runs out of elsifs.

When the interpreter runs out of elsifs, there may be an "else" case. If there is, and none of the if or elsif tests were true, the interpreter runs the else case.

Example

require "fileinto";
if header :contains "from" "coyote" {
   redirect "acm@example.edu";
} elsif header :contains ["subject"] ["$$$"] {
   discard;
} else {
   fileinto "INBOX";
}

Module

Core : Requires no import statement

Resources

RFC3028