selection

=3.2.2 c=
 * ===understand and use selection in pseudo-code and a procedural programming language, including the use of IF statements and CASE/SELECT statements;===


 * Switching Branches **

Nested **if** statements can take up a lot of space and can become difficult to understand. Instead of using lots of 'if' statements we can use the '**switch.. case'** statement, which evaluate the same variable with different tests. They look like:

{ **case** value1: code to be executed if true; break; **case** value2: code to be executed if true; break; **case** value3: code to be executed if true; break; **case** value4: code to be executed if true; break; **default**: code to be executed if false; }
 * switch ** (test-variable)

The switch statement takes a variable then tries to match its value from the various **case** options. The statement associated with each value in the case statement is then executed.

It is optional to add a **default** keyword, but it is good practice in case you have not covered all of the options, or if there is an error in the data.