redho home | products | services
Web Design Forums

Web Design Forums  


Web Hosting, Web Design, Software and Web Development Forums  
 FAQFAQ   MemberlistArchive  Log inLog in   RegisterRegister 
         

how to handle a situation with multiple cases


Goto page 1, 2  Next
 
Post new topic   Reply to topic    Web Design Forums -> JavaScript forum
View previous topic :: View next topic  
Author Message
kadamat



Joined: 01 Jun 2006
Posts: 88
LOL. *whistling sound of bomb dropping* can anyone tell me how to handle a situation where one might want to have multiple options or cases in a logical statement>? If else type stuff.
I have more than two cases though
  Reply with quote


Koplaf



Joined: 28 May 2006
Posts: 130
Use the boolean AND/OR statements
  Reply with quote
ovigo22



Joined: 15 May 2006
Posts: 130
If (condition) { action } else if (condition) { action } else { action }
Ahh .. stuff like that ..
  Reply with quote
Mupolan



Joined: 30 May 2006
Posts: 101
Or switch
  Reply with quote
ovigo22



Joined: 15 May 2006
Posts: 130
If ( this || orthis ) { action } else if ( this && andthis ) { action }
  Reply with quote
Roombor



Joined: 02 Jun 2006
Posts: 111
Sounds perfect for switch
  Reply with quote
AmeliaR



Joined: 31 May 2006
Posts: 142
kadamat: er... switch/case ?
  Reply with quote
kadamat



Joined: 01 Jun 2006
Posts: 88
So, could it be if (condition) { action } else if (condition) { action } else { action } -------------and then an infinite number of continued else { action } else { action } else { action } ?
  Reply with quote
ovigo22



Joined: 15 May 2006
Posts: 130
Yeah .. switch if the LHS of the comparison is always the same
kadamat, no, only one will ever get called
  Reply with quote
kadamat



Joined: 01 Jun 2006
Posts: 88
So switch is better for this?
  Reply with quote
ovigo22



Joined: 15 May 2006
Posts: 130
You can have as many 'else if' as you like
  Reply with quote


kadamat



Joined: 01 Jun 2006
Posts: 88
Cool... but it seems like extra keystrokes for a single situation
  Reply with quote
ovigo22



Joined: 15 May 2006
Posts: 130
Not necesarily .. switch is good for: if (X =1 ) { action } else if (X = 2) { action } else if (X = 3) {action} else {action} where the LHS of the condition is always the same
(think about multiple 'else' clasuses .. when would any but the first get executed?
  Reply with quote
kadamat



Joined: 01 Jun 2006
Posts: 88
Interesting
  Reply with quote
AmeliaR



Joined: 31 May 2006
Posts: 142
ovigo22, heh, well not to get offtrack, but for that I think a for loop would be better :-P
  Reply with quote
ovigo22



Joined: 15 May 2006
Posts: 130
Where?
  Reply with quote
kadamat



Joined: 01 Jun 2006
Posts: 88
Well, basically, I have a dropdown menu with four options. I need to set up a statement to handle all four. which would be the coolest/most elegant way to approach this?
  Reply with quote
ovigo22



Joined: 15 May 2006
Posts: 130
kadamat,switch would be as the LHS will always be the selectedIndex ..
(object full of functions == perl)
  Reply with quote
Gladis



Joined: 24 May 2006
Posts: 108
Perl must die
  Reply with quote
kadamat



Joined: 01 Jun 2006
Posts: 88
Thanks guys. So switch it is!
  Reply with quote
Klimapol



Joined: 27 May 2006
Posts: 134
ovigo22, t's also python.
Object full of functions is tasty.
  Reply with quote


kadamat



Joined: 01 Jun 2006
Posts: 88
So, it would be used like: selection = document.frmCheckMe.giveaway.value;
Then switch (selection)
?
Then case "name of item selected" :
Then the stuff I want to happen
Then the next case and so on?
  Reply with quote
Gladis



Joined: 24 May 2006
Posts: 108
Ok so...
Http://www.javascriptkit.com/javatutors/switch.shtml
  Reply with quote
kadamat



Joined: 01 Jun 2006
Posts: 88
Ah. ha! Thanks.
  Reply with quote
Klimapol



Joined: 27 May 2006
Posts: 134
Gladis, Are the javascript tutors or Java tutors.
?
  Reply with quote
Page 1 of 2 Goto page 1, 2  Next
Post new topic   Reply to topic    Web Design Forums -> JavaScript forum


Dubai Forums - Expat Help | Vegan Chat | Java Programming | Free 3D tutorials and 3d textures | Paris Forum | EU Forum
Free Dubai Classifieds | Free London Classifieds | Jobs in London

High Quality, Custom 3d animation and Web Design solutions Royal Quality Web Hosting Services Vegetarian and Animal Rights news

Powered by phpBB © 2001, 2005 phpBB Group