1int i = 63;
2
3switch (i)
4{
5 case int n when (n >= 100):
6 Console.WriteLine($"I am 100 or above: {n}");
7 break;
8
9 case int n when (n < 100 && n >= 50 ):
10 Console.WriteLine($"I am between 99 and 50: {n}");
11 break;
12
13 case int n when (n < 50):
14 Console.WriteLine($"I am less than 50: {n}");
15 break;
16}
1function getCategory(age) {
2 var category = "";
3 switch (true) {
4 case isNaN(age):
5 category = "not an age";
6 break;
7 case (age >= 50):
8 category = "Old";
9 break;
10 case (age <= 20):
11 category = "Baby";
12 break;
13 default:
14 category = "Young";
15 break;
16 };
17 return category;
18}
19getCategory(5); // will return "Baby"