This tutorial would give you a walkthrough of switch statement.
A switch statement allows certain blocks of code to be executed depending on the value of control expression.
Let's go through the different examples,
Ex 1: Basic example
Above mentioned e.g's are self explanatory
Ex 2: Tuple
In this example both the cases are true, so how can we make sure it continues to check if there is any other possibility,
Ex 3: Switch statement in Loop
A switch statement allows certain blocks of code to be executed depending on the value of control expression.
Let's go through the different examples,
Ex 1: Basic example
- if myTestVal is from 1-9
- if myTestVal is from 1-10
- '_' is ignored. This case is always true
Ex 2: Tuple
In this example both the cases are true, so how can we make sure it continues to check if there is any other possibility,
Ex 3: Switch statement in Loop
In the above example, value is found in the very first case. What if we don't want to iterate through the whole loop once the value is found?
Check this,
Hope this helps you.
No comments:
Post a Comment