A switch statement with varied case matches
The complete source of flowControl_switch_statement.ek9, compiled by the EK9 compiler. Shown on flowControl.html.
#!ek9 defines module site.flowControl.switchstatement defines function currentTemperature() as pure -> country as String <- temperature as Integer: Integer() if country == "GB" temperature := 20 else if country == "DE" temperature := 41 ASimpleSwitchStatement() as pure -> conditionVariable as Integer multiplier <- 5 //This is what we will vary based on the condition variable resultText1 <- String() switch conditionVariable case < 12 resultText1 :=? "Moderate" case > 10*multiplier resultText1 :=? "Very High" case 25, 26, 27 resultText1 :=? "Slightly High" case currentTemperature("GB"), 21, 22, 23, 24 resultText1 :=? "Perfect" default resultText1 :=? "Not Suitable" require resultText1? resultText2 <- String() //The same switch could have been written using given and when given conditionVariable when < 12 resultText2 :=? "Moderate" when > 10*multiplier resultText2 :=? "Very High" when 25, 26, 27 resultText2 :=? "Slightly High" when currentTemperature("GB"), 21, 22, 23, 24 resultText2 :=? "Perfect" default resultText2 :=? "Not Suitable" require resultText2?