• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use of operators in switch

 
Donald R. Cossitt
buckaroo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me what the logic behind JAVA not allowing the use of operators in the case method of switch is? EG

The alternative if | else if | else struct and their associated comparison operators are a pain in the ass to do and read later .
TIA
doco :roll:

(Marilyn added code tags)
[ February 02, 2003: Message edited by: Marilyn de Queiroz ]
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does any language?
A switch statement is supposed to be a static comparison. It allows the compiler to do certain optimizations. Otherwise you might as well use an if-else chain.
 
Donald R. Cossitt
buckaroo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Visual Basic, VBA, VBScript are ones I know of that allow that kind of behavior in Select Case myCase
 
Rich Raposa
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not serious, are you? Writing an "if/else if" is a pain in the ass compared to writing a switch statement?
Hmmm...next question, please.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic