This type of statement is also known as 'Else-if' ladder. It is useful when you want to check more than one condition within a code.
If the condition of any 'If' block is True, then the statements associated with that block are executed. If none of the conditions are True, then the statements inside default else block are executed.
Syntax of Else-if Statement
Flowchart of Else-If Statement
The following examples describe how to use the Else-If statement in PowerShell:
Example 1: In this example, we check a number is positive, negative, or zero.
Number is zero
Example 2: In this example, we find the grade of the student according to its percentage.
Example 3: In this example, we check the greatest number among the three variables.
The value of Variable 'c' is greater than the value of variable 'a' and 'b'.