[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Alternate for Case Code

Posted on 2003-11-13
9
Medium Priority
?
238 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Make the most of your online learning experience.
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…
Progress

656 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