Switch..Case语句问题。 [英] Switch..Case Statement Question.

查看:76
本文介绍了Switch..Case语句问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我以下Switch ... Case构造是否有效?

我想在Case语句中检查多个值而不用

明确列出每个值。

例如,案例1-35:工作?如果这样可行,那么它是否会考虑1到35之间的所有数字,包括1和35?如果以下内容有效,请告知




开关(状态){

案例1-35:

案例37:

做某事_1;

休息;

案例36:

做某事_2;

休息;

案例38-50:

做某事_3;

休息;

}

谢谢。

Andy。

解决方案

< blockquote> Andy于2005年2月28日在comp.lang.javascript中写道

有人能告诉我以下Switch ... Case构造是否有效?
我想在Case语句中检查多个值而不明确列出每个值。
例如,案例1-35:工作吗?如果这样可行,是否会考虑1到35之间的所有数字,包括1和35?如果以下内容有效,请告诉我/我:


你自己测试过吗?如果不是为什么不呢?

开关(状态){
案例1-35:
案例37:
做某事_1;
休息;



如果状态,则此部分将执行是-34或37,

因为1-35是34,我想。


但是请自己测试一下。

-

Evertjan。

荷兰。

(用我的电子邮件地址替换所有带点的十字架)


Andy说:


有人可以告诉我以下Switch ... Case构造是否有效?
我想要在没有明确列出每个值的情况下检查Case语句中的多个值。
例如,案例1-35:工作吗?如果这样可行,是否会考虑1到35之间的所有数字,包括1和35?如果以下内容有效,请告诉我/


开关(状态){
案例1-35:
案例37:
做某事_1 ;
休息;
案例36:
做某事_2;
休息;
案例38-50:
做某事_3;
休息;
}




用更少的精力和更少的等待时间,你可以自己测试一下你的样本代码。你的第一个案例将匹配任何状态

等于你的指数值-34(1-35)。


我道歉没有测试自己,浪费你的时间。你是否b $ b或其他任何人都知道一种方法来检查多个值,而不是

说明每个值,如果我想检查1到35之间的所有值

我该怎么做?


任何帮助都将不胜感激。


Can someone tell me if the following Switch...Case construct is valid?
I''m wanting to check for multiple values in the Case statement without
explicitly listing each values.
So for example, will case 1-35: work? If this would work, will it
consider all numbers between 1 and 35 inclusive of 1 and 35? Please let
me know if the following will work below:

switch(state){
case 1-35:
case 37:
do something_1;
break;
case 36:
do something_2;
break;
case 38-50:
do something_3;
break;
}
Thank you.
Andy.

解决方案

Andy wrote on 28 feb 2005 in comp.lang.javascript:

Can someone tell me if the following Switch...Case construct is valid?
I''m wanting to check for multiple values in the Case statement without
explicitly listing each values.
So for example, will case 1-35: work? If this would work, will it
consider all numbers between 1 and 35 inclusive of 1 and 35? Please let
me know if the following will work below:
did you test it yourself? If not why not?
switch(state){
case 1-35:
case 37:
do something_1;
break;



this part will execute if "state" is -34 or 37,
because 1-35 is 34, I think.

But please test it yourself.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)


Andy said:


Can someone tell me if the following Switch...Case construct is valid?
I''m wanting to check for multiple values in the Case statement without
explicitly listing each values.
So for example, will case 1-35: work? If this would work, will it
consider all numbers between 1 and 35 inclusive of 1 and 35? Please let
me know if the following will work below:

switch(state){
case 1-35:
case 37:
do something_1;
break;
case 36:
do something_2;
break;
case 38-50:
do something_3;
break;
}



With less effort and much less wait time, you could have just tested
your sample code yourself. Your first case will match any state that
equals your index value of -34 (1-35).


I apologize for not having tested myself and wasted your time. Do you
or anyone else knows of a way to check for multiple values without
stating each one like if I''d like to check all values from 1 through 35
how would i do it?

Any help will be appreciated.


这篇关于Switch..Case语句问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆