Switch Statement help for newbie

  • Thread starter Thread starter Roger Maynard
  • Start date Start date
R

Roger Maynard

This question probably seems dumb, but I'm converting a load of code
from VFox to C# under .NET (not before time !!)



I have a DO CASE... ENDCASE which tests for a variable lying in a
specific range. ie



DO CASE

CASE decimalnumb <8192

...Do this

CASE decimalnumb >=8192 AND decimalnumb<=16384

... Do This

....

Etc



ENDCASE



The switch operator seems to be the way to go - but how do I do the
comparative test??



I've done it with 'if' else.. at the moment, but this is cumbersome



Help!!



Roger Maynard
 
Hi Roger,

I've got "zero" knowledge about VFox... but it looks like
you've to convert it into "if" statements.
This question probably seems dumb, but I'm converting a load of code
from VFox to C# under .NET (not before time !!)



I have a DO CASE... ENDCASE which tests for a variable lying in a
specific range. ie



DO CASE

CASE decimalnumb <8192

into:
if( decimalnumb <8192 ) {
...Do this
}

CASE decimalnumb >=8192 AND decimalnumb<=16384

else if( decimalnumb >=8192 && decimalnumb<=16384 ) {
... Do This

}
else {
...

Etc
}

The switch operator seems to be the way to go - but how do I do the
comparative test??

"switch" statement supports only equals or "default" (as anything else).
I've done it with 'if' else.. at the moment, but this is cumbersome

I'm sure that way a right way (for "your sample code")

Regards

Marcin
 
Yes - but it would be a good syntax to have, wouldn't it. Imagine code like
this

switch(someval)
{
case <5:

case >25 && < 50:


}

I'm not sure how this will work for non-numeric types or types that don't
have the relational operators defined though
 
Oh Yes - I wish indeed !! Unfortunately it doesn't.

It's the first thing in my switch from VFOX which I have found hard
work.

Thanks guys for your feedback


+++++++++++++++++++++++


-----Original Message-----
From: Sriram Krishnan [mailto:[email protected]]
Posted At: 02 August 2004 14:40
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Switch Statement help for newbie
Subject: Re: Switch Statement help for newbie

Yes - but it would be a good syntax to have, wouldn't it. Imagine code
like
this

switch(someval)
{
case <5:

case >25 && < 50:


}

I'm not sure how this will work for non-numeric types or types that
don't
have the relational operators defined though
 
Sriram Krishnan said:
Yes - but it would be a good syntax to have, wouldn't it. Imagine code like
this

switch(someval)
{
case <5:

case >25 && < 50:


}

Personally I don't like that syntax - the expressions are "almost"
normal ones, but not quite because of the missing value. If there were
some change to make value a keyword, we could have:

case value < 5:
....
case value > 25 && value < 50:

which would be better.

Personally I'm happy to use if/else when switch/case is inappropriate
though.
 
Back
Top