Followers

Saturday, 5 July 2014

Using the Switch Statement

This tutorial would give you a walkthrough of switch statement.

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

  1. if myTestVal is from 1-9 
  2. if myTestVal is from 1-10
  3. '_' 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