473,569 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Syntax problem with the "SWITCH" Command

35 New Member
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 2737
gits
5,390 Recognized Expert Moderator Expert
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 Recognized Expert Top Contributor
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 New Member
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 New Member
Thanks also to epots9. I will try your suggestion too.
trbjr
Jul 16 '07 #5
gits
5,390 Recognized Expert Moderator Expert
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 New Member
gits,

Thanks for the clarification. That helps.

trbjr
Jul 16 '07 #7
gits
5,390 Recognized Expert Moderator Expert
... 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
1669
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"; case 1:
0
1282
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
3210
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
9
3139
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 GetCommand(EnumProviders provider) { switch( provider ) { case EnumProviders.ODBC: return new OdbcCommand();
2
1317
by: iincity | last post by:
hi,all, please see following: int index = 0 switch(index){ case 0 - 10: break; default: break;
3
1529
by: ken | last post by:
any function is equal to "Switch" in Java with VB thank heaps
6
2757
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 complier reduced my errors but I'm still having trouble. I think I have all the correct paths set but I'm not sure. F2PY gets further when I...
2
6852
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 response is n , the message Thank you anyway for your consideration is printed if response is h , the message Sorry, no help is currently...
0
1361
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 understand is with my switch subroutine. In the below code, if I select "d" or anything that is an invalid response, it loops correctly back to the menu....
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.