Solved

Alternate for Case Code

Posted on 2003-11-13
9
230 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
9 Comments
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
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
Comment Utility
I agree with whats sunny given
0
 
LVL 7

Expert Comment

by:alphaau
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 5

Expert Comment

by:g0rath
Comment Utility
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
Comment Utility
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 50 total points
Comment Utility
>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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
squareUp  challenge 22 104
allStar challenge 1 41
mapShare challenge 13 68
PHP question(s) about order of output 9 39
Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
This article will show, step by step, how to integrate R code into a R Sweave document
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now