Testing one variable against multiple conditions is what the switch statement is designed for. (Though in your example with only two conditions and no else path, the if statement is still shorter.)
switch a {
case 2..., 0:
print("...")
default:
break
}
I understand the motivation for the syntax, but I prefer alternate solutions such as tucking a complex group of conditions into a property or using a switch statement. In other words, I don't see enough of a need for the syntax.
Absolutely true, and one of the main reasons this would never make it past a pitch. However, if this were composed with other logical statements not pertaining to a, it could still be useful over a switch. (Prepare yourself for an ugly contrived example)
I just found the syntax to be interesting enough to share. Does anyone know if any language has implemented a similar feature? (Allowing the left hand side of a list of repeated logical expressions to be extracted out and applied to the list.)
I'm seeing this just before going to sleep, but this is going to keep me up for a while longer! Hats off to you @SDGGiesbrecht for the clever implementation!