An unless statement can be followed by an optional elsif statement, and then by another else statement.
This conditional statement is very useful in the case of multiple conditions.
You need to pay attention to the following points when using unless, elsif, else statements.
The unless statement can be followed by 0 or 1 else statements, but there must be an else statement after elsif.
The unless statement can be followed by 0 or 1 elsif statements, but they must be written before the else statement.
If one of elsif is executed successfully, the other elsif and else will no longer be executed.
The syntax format is as follows:
unless(boolean_expression 1){ # Execute when Boolean expression boolean_expression 1 is false}elsif( boolean_expression 2){ # Execute when Boolean expression boolean_expression 2 is true}elsif( boolean_expression 3){ # Execute when Boolean expression boolean_expression 3 is true }else{ #Execute when no condition is matched}
Executing the above program, the output result is:
The value of a is not 30