else

The else keyword executes an alternate statement block.

Purpose

A side statement within an if statement to execute an alternate statement block depending on a Boolean expression value.

Syntax

if (test) {statement}
 else {statement}

Description

The test can be any legal test as in the Java™ programming language. If the test returns true, the first statement block is executed and the else block is skipped over. If the test returns false, the first block is skipped over and the statement block that follows the else clause is executed.

A statement block can contain one or more statements. If it contains only one statement, the braces ({}) are not required. The else keyword and its statement block is optional.