Skip to content

Selection with switch

Many languages provide you with a switch or case statement that can be used to choose between different paths based upon matching values.

Switch illustration code

Example

using static SplashKitSDK.SplashKit;
// You can create boolean variables to store true/false values.
// There are also keywords for true and false
bool ready = false;
WriteLine(" a - say hello");
WriteLine(" b - say bye");
WriteLine(" c - say Ni!");
WriteLine();
Write("Enter option: ");
string line = ReadLine();
// Switch to the case that matches the value in line
switch(line)
{
case "A":
case "a":
WriteLine("Hello");
break;
case "B":
case "b":
WriteLine("Bye");
break;
case "C":
case "c":
WriteLine("Ni!");
break;
case "D":
case "d":
WriteLine("Superpowers unlocked!");
break;
default:
WriteLine("Please choose one of the indicated options");
break;
}