?
Solved

Alternate for Case Code

Posted on 2003-11-13
9
Medium Priority
?
240 Views
Last Modified: 2010-04-17
     Is it possible to replace the code between the braces with different code that is not a case statement.  I mean engineer a different way to do the same thing.  Possibly with a series of if statements or something such as "if B or b then x,  if V or v then y,  If Q or q then z."  If so what would the syntax be?  What code could replace this and plug into the same spot.  
{
                case 'B':
                case 'b':
                    filer.buildAFile();
                    break;
                case 'V':
                case 'v':
                    filer.viewAFile();
                    break;
                case 'Q':
                case 'q':
                    done = true;
                    break;
                default:
                    System.out.println("That is not a valid choice.");
                    break;
            }
0
Comment
Question by:rockyisin
6 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9745610
Hi rockyisin,
> {
>                 case 'B':
>                 case 'b':
>                     filer.buildAFile();
>                     break;
>                 case 'V':
>                 case 'v':
>                     filer.viewAFile();
>                     break;
>                 case 'Q':
>                 case 'q':
>                     done = true;
>                     break;
>                 default:
>                     System.out.println("That is not a valid choice.");
>                     break;
>             }

you did not specify the switch !!!!

I assume switch (a)

if ( a == 'B' || a == 'b' )
    filer.buildAFile();
else
    if ( a == 'V' || a == 'v' )
           filer.viewAFile();
    else
        if ( a == 'Q' || a == 'q' )
           done = true;
        else
            System.out.println("That is not a valid choice.");

this should give you an idea though sytax is Cish

Cheers!
Sunny:o)
0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9745978
I agree with whats sunny given
0
 
LVL 7

Expert Comment

by:Alpha Au
ID: 9746007
the syntax you used is java like syntax,

the vb syntax should be

select case Lcase(switchtext)
   case "b":
      filer.buildAFile();
   case "v":
      filer.viewAFile();
   case "q"
   else
      System.out.println("That is not a valid choice.");
end select

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Expert Comment

by:g0rath
ID: 9747597
or...

if using C/C++
a = toupper(a);
Java String
a.toUpperCase()

if ( a == 'B')
    filer.buildAFile();
else
    if ( a == 'V')
           filer.viewAFile();
    else
        if ( a == 'Q')
           done = true;
        else
            // whatever your message
0
 

Author Comment

by:rockyisin
ID: 9751955
My question is:  Could I do what the Case statement does a different way.. maybe using a series of  "if" statements.  Can I cut out this case statement and replace it with a series of if statements?  What would this look like?
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 200 total points
ID: 9753054
>Could I do what the Case statement does a different way.. maybe using a series of  "if" statements
yes, you can do it
>Can I cut out this case statement and replace it with a series of if statements?  
Yes
>What would this look like?

if ( a == 'B' || a == 'b' )
    filer.buildAFile();
else
    if ( a == 'V' || a == 'v' )
           filer.viewAFile();
    else
        if ( a == 'Q' || a == 'q' )
           done = true;
        else
            System.out.println("That is not a valid choice.");
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question