Conditional Statements in PowerShell
Conditional statements are used to execute code based on certain conditions. PowerShell supports the if, else if, and else statements. Here's an example:
$age = 30
if ($age -lt 18) {
Write-Host "You are not old enough to vote."
}
elseif ($age -ge 18 -and $age -lt 65) {
Write-Host "You are eligible to vote."
}
else {
Write-Host "You are eligible to vote, but not required to."
}
In this example, we check the value of the $age variable and display a message based on whether the person is eligible to vote or not.
No comments:
Post a Comment