?
Solved

Alternate for Case Code

Posted on 2003-11-13
9
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 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