when I execute this code just the print("it is greater than zero")
gets executed but I have two cases where it's true, I've tried to use the fallthrough
keyword but it executes the next case block even if it's false, no matter what,
which in turn raises another question, when should I use fallthrough
keyword? if I want to forcefully execute the next block why don't just insert the code into the same block where fallthrough
sits?
Is there any way that the example below could print all cases that evaluate to true and still rule out all cases that evaluate to false?
let number = 1
switch number {
case _ where number > 0:
print("it is greater than zero")
case _ where number < 2:
print("it is less than two")
case _ where number < 0:
print("it is less than zero")
default:
print("default")
}
Thank you in advance for your answers!