- PowerShell - Home
- PowerShell - Overview
- PowerShell - Environment Setup
- PowerShell - Cmdlets
- PowerShell - Files and Folders
- PowerShell - Dates and Timers
- PowerShell - Files I/O
- PowerShell - Advanced Cmdlets
- PowerShell - Scripting
- PowerShell - Special Variables
- PowerShell - Operators
- PowerShell - Looping
- PowerShell - Conditions
- PowerShell - Array
- PowerShell - Hashtables
- PowerShell - Regex
- PowerShell - Backtick
- PowerShell - Brackets
- PowerShell - Alias
- PowerShell Useful Resources
- PowerShell - Quick Guide
- PowerShell - Useful Resources
- PowerShell - Discussion
Powershell - Nested If Else Statement
It is always legal to nest if-else statements which means you can use one if or elseif statement inside another if or elseif statement.
Syntax
The syntax for a nested if...else is as follows −
if(Boolean_expression 1) {
// Executes when the Boolean expression 1 is true
if(Boolean_expression 2) {
// Executes when the Boolean expression 2 is true
}
}
You can nest elseif...else in the similar way as we have nested if statement.
Example
$x = 30
$y = 10
if($x -eq 30){
if($y -eq 10) {
write-host("X = 30 and Y = 10")
}
}
This will produce the following result −
Output
X = 30 and Y = 10
powershell_conditions.htm
Advertisements