The switch is one of the control flow statements that which perform different computations depending on the value of the given variable.
This is the syntax of the switch statement in the PNP language:
caso <variable> seja
<value-1>: <block of instructions when variable = value1>
<value-2>: <block of instructions when variable = value2>
<value-2>: <block of instructions when variable = value3>
senao: <block of instructions default>
fim
The default branch can be omitted. A switch statement can have multiple branches. Each branch can only be computed if its respective condition value is true and all the other branches won't be computed. The computation of the switch statement is very similar to an if statement #11. The equivalent of the switch example in an if statement is as follows:
se (variable = value1) entao
<block of instructions when variable = value1>
senao se (variable = value2) entao
<block of instructions when variable = value2>
senao se (variable = value3) entao
<block of instructions when variable = value3>
senao
<block of instructions default>
fim
The switch is one of the control flow statements that which perform different computations depending on the value of the given variable.
This is the syntax of the switch statement in the PNP language:
The default branch can be omitted. A switch statement can have multiple branches. Each branch can only be computed if its respective condition value is true and all the other branches won't be computed. The computation of the switch statement is very similar to an if statement #11. The equivalent of the switch example in an if statement is as follows: