Switch statement
A tool to facilitate complex if ... else if statements.
Last updated
Was this helpful?
A tool to facilitate complex if ... else if statements.
Last updated
Was this helpful?
The switch
and case
statements cannot be used most of the time since they are not in the Norm
.
It could be useful in some exams, and you can use it there since there is no Norm
during the exams.
The switch
and case
statements help control complex conditional and branching operation.
I'll take as example one of the exercises of the exam rank 02 - level 2
, the one, go read the subject there, then come back here.
I'll first write it using if and else if statements, then I'll write the exact same thing using the switch
statement.
As you can see, both codes are pretty similar, but I personally think that the switch
statement is clearer and easier to write.
The switch statement takes a bit more place but could be useful in some cases.
You can find more details about it .