Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Referring to cases

  1. #1
    Member
    Join Date
    Feb 2011
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Referring to cases

    If I have a switch-case block like:

    switch(i){
     
    case1:
    blah1;
    break;
     
    case2:
    blah2;
    break
     
    case3:
    blah3;
    break;
    }

    is there anyway to refer to the current case the program is in? For example, if I wanted to initialize an int inside "case2:" to 2, or initialize an int inside "case3" to 3.


  2. #2
    Member
    Join Date
    Nov 2011
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Referring to cases

    No, there is no such thing.

    Spring 3
    Last edited by cafeteria84; January 22nd, 2012 at 03:00 PM.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,719
    Thanks
    45
    Thanked 1,974 Times in 1,948 Posts

    Default Re: Referring to cases

    Can you explain what you want to use the code for and why you think you have the need you describe to have variables initialized for specific case values?

Similar Threads

  1. Switching letter-cases from user input; why is not working?
    By Kimiko Sakaki in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 27th, 2011, 07:48 AM
  2. Converting Cases Help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 27th, 2010, 12:07 PM