Switch

You can use switch statements in two ways in Imba:

var number = 1 var numberString = switch number when 0 "zero" when 1 "one" else "not 1 nor 0" # compact var numberString2 = switch number when 0 then "zero" when 1 then "one" else "not 1 nor 0" # you can also mix them var numberString3 = switch number when 0 then "zero" when 1 "one" else "not 1 nor 0" var number = 1; switch (number) { case 0: { numberString = "zero"; break; } case 1: { numberString = "one"; break; } default: var numberString = "not 1 nor 0"; }; // compact switch (number) { case 0: { numberString2 = "zero";break; } case 1: { numberString2 = "one";break; } default: var numberString2 = "not 1 nor 0"; }; // you can also mix them switch (number) { case 0: { numberString3 = "zero";break; } case 1: { numberString3 = "one"; break; } default: var numberString3 = "not 1 nor 0"; };

As you see, else stands for default. Isn't it clearer?