• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Switch-Case

 
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following sentence is from Jqplus.I can't understand the meaning of the sentence in black.Please explain along with code e.g.
The body of a switch statement must be a block. Any statement immediately contained by the block may be labeled
with one or more case or default labels. These labels are said to be associated with the switch statement, as are the
values of the constant expressions in the case labels.

Bye.
Viki.

------------------
Count the flowers of ur garden,NOT the leafs which falls away!
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any label in Java is specified by a colon. So if you write, case 1:, this is called a case label. And the 1 is called the constatnt of the case label.
A switch statement looks like this,
//some code.
switch (i) //consider i as an int.
{
case 1:
System.out.println("The value is 1");
case 2:
System.out.println("The value is 2");
default:
System.out.println("Some other value");
}
//some code.
Hope this helps.
Ahmed.
 
Vikrama Sanjeeva
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Ahmed.I was not reading carefully.
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
reply
    Bookmark Topic Watch Topic
  • New Topic