This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int i = 1; | |
switch (i) | |
{ | |
case 1: | |
Console.WriteLine("One"); | |
break; | |
case 2: | |
Console.WriteLine("Two"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$i = 1; | |
switch ($i) | |
{ | |
1 { | |
write-host "one" | |
break | |
} | |
2 { | |
write-host "two" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch("hello") #will match uppercase | |
{ | |
"HELLO" {write-host "Uppercase" -ForegroundColor Magenta;break} | |
"hello" {write-host "lowercase" -ForegroundColor green;break} | |
} | |
switch("hello") #will NOT match h* | |
{ | |
"h*" {write-host "wildcard" -ForegroundColor Magenta;break} | |
"hello" {write-host "lowercase" -ForegroundColor green;break} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$num = 4 | |
Switch($num) | |
{ | |
{$num -lt 5} {write-host "less than 5!" -ForegroundColor Magenta;break} | |
{$num -lt 10} {write-host "less than 10!" -ForegroundColor green;break} | |
{$num -lt 15} {write-host "less than 15!" -ForegroundColor cyan;break} | |
default {write-host "greater than or equal to 15" -ForegroundColor yellow} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$num = 4 | |
Switch($num) | |
{ | |
{$num -lt 5} {write-host "less than 5!" -ForegroundColor Magenta} | |
{$num -lt 10} {write-host "less than 10!" -ForegroundColor green} | |
{$num -lt 15} {write-host "less than 15!" -ForegroundColor cyan} | |
default {write-host "greater than or equal to 15" -ForegroundColor yellow} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$nums = 1..15 | |
foreach($num in $nums) | |
{ | |
Switch($num) | |
{ | |
{$num -lt 5} {write-host "$num is less than 5!" -ForegroundColor Magenta} | |
{$num -lt 10} {write-host "$num is less than 10!" -ForegroundColor green} | |
{$num -lt 15} {write-host "$num is less than 15!" -ForegroundColor cyan} | |
default {write-host "$num is greater than or equal to 15" -ForegroundColor yellow} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$nums = 1..15 | |
Switch($nums) | |
{ | |
{$_ -lt 5} {write-host "$_ is less than 5!" -ForegroundColor Magenta} | |
{$_ -lt 10} {write-host "$_ is less than 10!" -ForegroundColor green} | |
{$_ -lt 15} {write-host "$_ is less than 15!" -ForegroundColor cyan} | |
default {write-host "$_ is greater than or equal to 15" -ForegroundColor yellow} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$nums = 1..15 | |
Switch($nums) | |
{ | |
{$_ -lt 5} {write-host "$_ is less than 5!" -ForegroundColor Magenta;break} | |
{$_ -lt 10} {write-host "$_ is less than 10!" -ForegroundColor green;break} | |
{$_ -lt 15} {write-host "$_ is less than 15!" -ForegroundColor cyan;break} | |
default {write-host "$_ is greater than or equal to 15" -ForegroundColor yellow} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$nums = 1..15 | |
Switch($nums) | |
{ | |
{$_ -lt 5} {write-host "$_ is less than 5!" -ForegroundColor Magenta;continue} | |
{$_ -lt 10} {write-host "$_ is less than 10!" -ForegroundColor green;continue} | |
{$_ -lt 15} {write-host "$_ is less than 15!" -ForegroundColor cyan;continue} | |
default {write-host "$_ is greater than or equal to 15" -ForegroundColor yellow} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch -casesensitive ("hello") #makes it a -ceq | |
{ | |
"HELLO" {write-host "Uppercase" -ForegroundColor Magenta} | |
"hello" {write-host "lowercase" -ForegroundColor green} | |
"h*" {write-host "wildcard" -ForegroundColor Magenta} | |
} | |
switch -wildcard ("hello") #makes it a -like | |
{ | |
"HELLO" {write-host "Uppercase" -ForegroundColor Magenta} |
OlderNewer