Using goto in a switch

In a previous post, I explained how to use the evil goto keyword. Here I would like to show you a special use of it. When you are in a switch block and some cases must execute their own actions plus the actions of another case. Then you can chain the goto and case keywords (Figure 1).

goto-case

Figure 1

Each case is actually like a label, meaning that the sequence will directly continue at the case you specify. Here below is the result of the above code (Figure 2).

goto-case-result

Figure 2

Advertisements