473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Syntax problem with the "SWITCH" Command

35
There is something I don't understand about the syntax of the SWITCH command. Here is the code that does not work:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     switch (msgtype == )  {
  3.         case '0' :
  4.             title = "Error Condition -- see Tom ";
  5.             break;
  6.         case '1' :
  7.             title = "Domestic Program";  
  8.             break;
  9.         case '2' :
  10.             title = "Ken ";
  11.             break;
  12.         case '3' :
  13.             title = "Tom";
  14.             break;
  15.         case '4' :
  16.             title = "ISSA Preparers";                   
  17.             break;
  18.         case '5' :
  19.             title = "Unanticipated Condition Found-- see Tom ";
  20.             break;
  21.         default :
  22.             title = "msgtype has unexpected value";
  23.     }        
  24.  
  25.  
Is my error that I have "==" following msgtype in the expression?

Should I have double quotes (") around each case value?

Can anyone recommend a good javascript book that shows the finer points of javascript syntax?

TIA

trbjr
Jul 16 '07 #1
7 2723
gits
5,390 Expert Mod 4TB
hi ...

correct usage is as follows:

Expand|Select|Wrap|Line Numbers
  1. switch (variable) {
  2. case var_value_1:
  3.     // do something;
  4.     break;
  5. case var_value_2:
  6.     // do something;
  7.     break;
  8. default:
  9.     // do something;
  10.     break;
  11. }
i prefer to add the break to the default-case ... but it is not required. whether you have to add quotes to the var_values depends on the type of your var that is 'switched' ... in case you put a number in ... you don't need to ... when it is a stringvalue you may use single- or double-quotes

kind regards

ps: good book is the david flanagan 'javascript: the definitive guide' - book, be sure to get an actual one ... i think there is the 5th edition already
Jul 16 '07 #2
epots9
1,351 Expert 1GB
There is something I don't understand about the syntax of the SWITCH command. Here is the code that does not work:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     switch (msgtype == )  {
  3.         case '0' :
  4.             title = "Error Condition -- see Tom ";
  5.             break;
  6.         case '1' :
  7.             title = "Domestic Program";  
  8.             break;
  9.         case '2' :
  10.             title = "Ken ";
  11.             break;
  12.         case '3' :
  13.             title = "Tom";
  14.             break;
  15.         case '4' :
  16.             title = "ISSA Preparers";                   
  17.             break;
  18.         case '5' :
  19.             title = "Unanticipated Condition Found-- see Tom ";
  20.             break;
  21.         default :
  22.             title = "msgtype has unexpected value";
  23.     }        
  24.  
  25.  
Is my error that I have "==" following msgtype in the expression?

Should I have double quotes (") around each case value?

Can anyone recommend a good javascript book that shows the finer points of javascript syntax?

TIA

trbjr
try this:
Expand|Select|Wrap|Line Numbers
  1.  
  2.     switch (msgtype)  { //remove the ==
  3.         case '0' :
  4.             title = "Error Condition -- see Tom ";
  5.             break;
  6.         case '1' :
  7.             title = "Domestic Program";  
  8.             break;
  9.         case '2' :
  10.             title = "Ken ";
  11.             break;
  12.         case '3' :
  13.             title = "Tom";
  14.             break;
  15.         case '4' :
  16.             title = "ISSA Preparers";                   
  17.             break;
  18.         case '5' :
  19.             title = "Unanticipated Condition Found-- see Tom ";
  20.             break;
  21.         default :
  22.             title = "msgtype has unexpected value";
  23.     }        
  24.  
  25.  
minor edit (but a big problem).

good luck
Jul 16 '07 #3
trbjr
35
Thanks, Gits. I think that will do it.

Also, I appreciate the book tip. What did you mean by your comment: "...be sure to get an actual one..."?

trbjr
Jul 16 '07 #4
trbjr
35
Thanks also to epots9. I will try your suggestion too.
trbjr
Jul 16 '07 #5
gits
5,390 Expert Mod 4TB
Thanks, Gits. I think that will do it.

Also, I appreciate the book tip. What did you mean by your comment: "...be sure to get an actual one..."?

trbjr
the 5th edition ... not one before ... the 5th has a lot more on oo-javascript if you need it sometimes ... and more dom-handling too ;) ...

kind regards
Jul 16 '07 #6
trbjr
35
gits,

Thanks for the clarification. That helps.

trbjr
Jul 16 '07 #7
gits
5,390 Expert Mod 4TB
... glad to be able to help you ... in case you have more questions come back and we will help you again ;)

kind regards
Jul 16 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jamie Wright | last post by:
I have using a 'switch' to retrieve the name of the website section through sending a 'section' integer... function title($section) { switch ($section) { case 0: $output = "Introduction";...
0
by: Christian Seberino | last post by:
How add "-L path" switch when building C extension? I want compilation to use a DIFFERENT version of a library in a DIFFERENT directory than usual. Thanks. Chris
12
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
9
by: Steve Bering | last post by:
I am a csharp newbie and am trying to work through some code and have gotten myself stuck in a loop. Any help would be appreciated. I have the following code in place: public IDcCommand...
2
by: iincity | last post by:
hi,all, please see following: int index = 0 switch(index){ case 0 - 10: break; default: break;
3
by: ken | last post by:
any function is equal to "Switch" in Java with VB thank heaps
6
by: Sile | last post by:
Hello, I'm trying to get f2py working from the command line on windows XP. I have mingw32 as my C complier (after some advice on a previous thread) and Compaq Visual Fortran 6.5. Changing my C...
2
NewYorker
by: NewYorker | last post by:
Write a switch statement that tests the value of the char variable response and performs the following actions: if response is y , the message Your request is being processed is printed if ...
0
by: Sudz28 | last post by:
Greetings! I am attempting to write a program that will allow a user to manipulate data read from a file, and am obviously in no way near finished. However, one problem I'm having that I don't...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.