7/31/08

When to use Switch-case statement

In a situation where, there are a number of conditions to be checked for performing different actions, we tend to use a chain of IF - ELSE IF statements. Such a code looses its readability, making understanding and maintenance difficult. Also if while writing such a code if the braces are not matched properly, some conditions does not produce the required output. But in such a cases if Switch Case statements are used, the code becomes very easy to understand and maintain.

Use Switch Case Statements where ever possible instead of IF - ELSE IF statements

No comments: