Welcome to MSDN Blogs Sign in | Join | Help

What if IF isn't cutting it? How about a switch?

So I have been playing with the IF statement for quite some time now and from time to time it fails me. Generally it fails me when I am trying to do three or more conditions. I attempted to do some nested IF statements and Jon from our developer support group steered me to the straight and narrow. :-) So don't make fun of me for my mediocre coding skills. :-)

So instead of doing an IF, how does this look for cleaner code? You can then take on as many different scenarios as you want.

var prefix = "";
switch (crmForm.all.customertypecode.SelectedText)
{
     case "Manufacturer":
               prefix="MFG";    
               break;
     case "Investor":
               prefix="INV";
               break;

     case "Press":
               prefix="SCUM";
               break;
     default:
               break;
}

 

Here is a link to the MSDN page that has a ton more details on the switch command. Enjoy!

switch Statement (JScript 5.6)

Published Monday, June 25, 2007 11:30 AM by Ben Vollmer
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Mitch Milam’s Microsoft Discussions » Blog Archive » Using the JavaScript Switch Statement

# re: What if IF isn't cutting it? How about a switch?

Thanks!

I was a big If..then user back in the days of my TRS-80 CoCo, and then, when I discovered the switch statement (in college, a few years and an IBM clone later), I was a changed man.  Clean, concise, and easy to use!

Jeff

Monday, August 06, 2007 6:02 PM by Jeff Dempsey

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker