Submitted by Caleb Thorne on Sat, 11/29/2014 - 11:29am.
The switch statement is a common control structure in programming languages. You will have undoubtedly seen a few if you spend any time working with Drupal modules or themes. Switch statements love to hangout with a theme's template.php file in preprocess hooks. Consider, if you will, the following:
Submitted by Caleb Thorne on Wed, 06/13/2012 - 7:14am.
Many languages support a control structure called the switch statement that is an alternative for if/else-if. Python, however, has no switch statement. Does that mean we must always resort to using a sequence of if/elif? Not necessarily! Python uses one of the most efficient hashing algorithms for it's dictionary type. We can use a dictionary to create a type of switch statement that is both efficient and very elegant. Consider the following sequence of if/elif to find a holiday for a given month.