Previous Topic: The if StatementNext Topic: The switch Statement


The else if Statement

For multiple outcomes, you can nest if/else statements. However, the logic can become cumbersome to follow with too many nestings. You can therefore use the following construction for a series of if/else statements:

if (Boolean_expression_1)
	statement_1
else if (Boolean_expression_2)
	statement_2
else if (Boolean_expression_3)
	statement_3
...
else if (Boolean_expression_n)
	statement_n
else
	statement_else

The final else statement is optional. It merely specifies code to be executed if none of the Boolean expressions is True.