Switch Statement
This lesson introduces the switch statement, its basic syntax and how it is written using an example
We'll cover the following...
Switch Case Construct #
Typically this is required when based on different values of a particular expression, different actions need to be performed. The basic construct of a switch case looks as follows:
Press + to interact
switch (expression){case constant-expression:statement; //statement(s) execute if constant-expression is truebreak; //exit the switch blockdefault: //the code inside default is run when no other cases matchstatement;break;}
-
In the code block above the
expression
can have multiple values. Essentially:- string
- integer
-
case
...