Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

switch case valid?

 
Timothy Leong
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, suppose I have option 1-6 that perform the same operation. can I use the following?



using case 1-6 instead?

Thanks
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try to compile it?

 
Timothy Leong
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tired compile it and run. The program still works.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I din't understand you quesion.
You want this?

case -5:
break;
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
case 1-6
is the same as
case -5

so if you want 6 options
use
case 1:
case 2:
.
.
.
case 6:
....
break;
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The syntax for Java's switch statement can be found in this section of the Java Language Specification. As David pointed out, 1-6 is a compile time expression with value -5.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic