473,511 Members | 17,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Switch ?

In my case statements I need to evaluate a number but it doesn't like
my syntax.
Example:
x= 45
Switch (x){
case > 7 < 10:
<code>
break;
case > 11 < 50
<code>
break;
default:
break;

}

It does not like the < or > than comparison operators. I know there
has to be a way to do this.

Nov 17 '05 #1
4 1433
You could always use an if statement:

x=45;
if (x > 7 && x < 10)
<code>
else if (x > 11 && x < 50)
<code>
else
<default>
"John S" <jo********@cinfin.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
In my case statements I need to evaluate a number but it doesn't like
my syntax.
Example:
x= 45
Switch (x){
case > 7 < 10:
<code>
break;
case > 11 < 50
<code>
break;
default:
break;

}

It does not like the < or > than comparison operators. I know there
has to be a way to do this.

Nov 17 '05 #2


"John S" wrote:
In my case statements I need to evaluate a number but it doesn't like
my syntax.
Example:
x= 45
Switch (x){
case > 7 < 10:
<code>
break;
case > 11 < 50
<code>
break;
default:
break;

}

It does not like the < or > than comparison operators. I know there
has to be a way to do this.

Sorry, can't do it with c#. Only finite values can be used. You can stack
cases but no ranges.

If you search on "switch-statement ???", you will find a decent post
explaining this.

Dwight
Nov 17 '05 #3
John S <jo********@cinfin.com> wrote:
In my case statements I need to evaluate a number but it doesn't like
my syntax.
Example:
x= 45
Switch (x){
case > 7 < 10:
<code>
break;
case > 11 < 50
<code>
break;
default:
break;

}

It does not like the < or > than comparison operators. I know there
has to be a way to do this.


Yes, with "if":

if (x > 7 && x < 10)
{
....
}
else if (x > 11 && x < 50)
{
....
}

switch/case is for specific values, not ranges.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
I would also suggest picking up a C# syntax book and learn it rather than
inventing your own. saves yourself a lot of aggravation in the long run.

"John S" wrote:
In my case statements I need to evaluate a number but it doesn't like
my syntax.
Example:
x= 45
Switch (x){
case > 7 < 10:
<code>
break;
case > 11 < 50
<code>
break;
default:
break;

}

It does not like the < or > than comparison operators. I know there
has to be a way to do this.

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2586
by: Rudi Hansen | last post by:
I dont seem to be able to find the switch statement in Python. I would like to be able to do switch(var) case 1 : print "var = 1" case 2: print "var = 2"
10
10882
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a...
5
3106
by: Bryan Parkoff | last post by:
C++ programmers and I tried to experience by writing 65536 switch cases. It is too large for Windows XP and other operating system to handle. It looks like that JMP Table obtains 256K bytes for...
10
9554
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
65
6612
by: He Shiming | last post by:
Hi, I just wrote a function that has over 200 "cases" wrapped in a "switch" statement. I'm wondering if there are performance issues in such implementation. Do I need to optimize it some way? ...
3
19727
by: pgraeve | last post by:
I am a convert from VB to C# so bear with me on this "conversion" question C# switch statement seems to be the closest relative to VB's Select Case. I used VB's Select Case statement liberally. ...
11
3130
by: ME | last post by:
In C# the following code generates a compiler error ("A constant value is expected"): public void Test(string value) { switch (value) { case SimpleEnum.One.ToString(): MessageBox.Show("Test...
12
12256
by: | last post by:
Is it fine to call another method from Switch? Eg. Switch (stringVar) { case ("a"): somVar = "whatever"; Another_Method(); //call another method return;
7
3349
by: Rohit | last post by:
Hi, I am working on a switch module which after reading voltage through a port pin and caterogizing it into three ranges(open,low or high), passes this range to a function switch_status() with...
11
4932
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Can switch statements be nested? I've got a large routine that runs off of a switch statement. If one of the switches in switch #1 is true, that enters switch statement #2. Some of the...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.