An if statement can be followed by an optional elsif statement, and then by another else statement.
This conditional judgment statement is very useful in the case of multiple conditions.
You need to pay attention to the following points when using if, elsif, else statements.
The if statement can be followed by 0 or 1 else statements, but elsif must be followed by an else statement.
The if statement can be followed by 0 or 1 elsif statements, but they must be written before the else statement.
If one of elsif executes successfully, the other elsif and else will no longer be executed.
The syntax format is as follows:
if(boolean_expression 1){ # Execute when Boolean expression boolean_expression 1 is true}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{ #Executed when all conditions of the Boolean expression are false}
Executing the above program, the output result is:
The value of a is 100