继续开关 [英] continue with switch

查看:77
本文介绍了继续开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

''继续''切换实际上与外部''while''

循环相关联。这种行为是否可行?


int ch =''\ n'';

while(true){

switch (ch){

case''\ n'':cout<< "测试英寸;继续;

}

}


上述循环在gcc版本2.96 20000731(红色
)中无休止地执行
Hat Linux 7.3 2.96-110)"。

解决方案

" v4vijayakumar" < V4 *********** @ yahoo.com>写道:

''继续''切换实际上与外部''while''
循环相关联。这种行为是否可行?

int ch =''\ n'';
while(true){
switch(ch){
case'' \\ n'':cout<< "测试英寸;继续;
}
}




我不知道它是否可以在C ++下移植,这就是你的代码

实际上是。在这个新闻组中我们讨论ISO C,是的,在那个

语言中,任何continue语句都不适用于switch语句,但

到continue'的最近的周围循环语句,如果有的话。


Richard


v4vijayakumar写道:

'''继续''开关实际上与外部''while''
循环相关联。这种行为是否可行?

int ch =''\ n'';
while(true){
switch(ch){
case'' \\ n'':cout<< "测试英寸;继续;
}



上述循环在gcc版本2.96 20000731(Red
Hat Linux 7.3 2.96-110)中无休止地执行。


尝试这个代码的和平:

int main(){

int ch =''a'';

int i = 0;

while(1){

switch(ch){

case'' a'':printf(" i =%d,a \ n,i); CH = B;继续;打破;

case''b'':printf(" i =%d,b\ n,i); CH = C;继续;

}

i ++;


}

返回0;

}


你会看到,两个printf语句都被执行了。因此,切换中的继续

将跳转到下一个大小写区块,即* b $ b执行*并进行*更新比较。后者意味着,如果你用ch =''d''替换ch ='''b'',那么只有第一个printf

被执行。


Richard Bos写道:

" v4vijayakumar" < V4 *********** @ yahoo.com>写道:

''继续''切换实际上与外部''while''
循环相关联。这种行为是否可行?

int ch =''\ n'';
while(true){
switch(ch){
case'' \\ n'':cout<< "测试英寸;继续;
}
}



我不知道它是否可以在C ++下移植,这就是你的代码实际上是什么。在这个新闻组中,我们讨论了ISO C,是的,在那个
语言中,任何continue语句都不适用于switch语句,而是
到continue'最接近的环绕语句,如果有的话。

理查德




真的吗?

切换语句中的任何中断实际上都分配给了

切换语句(它留下选择语句切换并继续

,切换后的第一个语句)而不是任何周围的循环。

同样适用于继续恕我直言。


''continue'' within switch actually associated with the outer ''while''
loop. Is this behavior protable?

int ch = ''\n'';
while (true) {
switch(ch) {
case ''\n'': cout << "test"; continue;
}
}

the above loop executed endlessly in "gcc version 2.96 20000731 (Red
Hat Linux 7.3 2.96-110)".

解决方案

"v4vijayakumar" <v4***********@yahoo.com> wrote:

''continue'' within switch actually associated with the outer ''while''
loop. Is this behavior protable?

int ch = ''\n'';
while (true) {
switch(ch) {
case ''\n'': cout << "test"; continue;
}
}



I have no idea if it''s portable under C++, which is what your code
actually is. In this newsgroup we discuss ISO C, and yes, in that
language any continue statements do not apply to a switch statement, but
to the continue''s closest surrounding loop statement, if there is any.

Richard


v4vijayakumar wrote:

''continue'' within switch actually associated with the outer ''while''
loop. Is this behavior protable?

int ch = ''\n'';
while (true) {
switch(ch) {
case ''\n'': cout << "test"; continue;
}
}

the above loop executed endlessly in "gcc version 2.96 20000731 (Red
Hat Linux 7.3 2.96-110)".



try this peace of code:
int main() {
int ch = ''a'';
int i=0;
while (1) {
switch(ch) {
case ''a'': printf("i=%d, a\n",i); ch=''b''; continue; break;
case ''b'': printf("i=%d, b\n",i); ch=''c''; continue;
}
i++;

}
return 0;
}

you will see, that both printf-statements are executed. The continue
in switch is therefore to jump to the next case block, which is
executed *with* renewed comparison. The latter means, that if you
replace ch=''b'' by ch=''d'' or something, then only the first printf
is executed.


Richard Bos wrote:

"v4vijayakumar" <v4***********@yahoo.com> wrote:

''continue'' within switch actually associated with the outer ''while''
loop. Is this behavior protable?

int ch = ''\n'';
while (true) {
switch(ch) {
case ''\n'': cout << "test"; continue;
}
}


I have no idea if it''s portable under C++, which is what your code
actually is. In this newsgroup we discuss ISO C, and yes, in that
language any continue statements do not apply to a switch statement, but
to the continue''s closest surrounding loop statement, if there is any.

Richard



really?
Any break inside a switch statement is actually assigned to the
switch statement (it leaves the choice statement switch and continues
with the first statement after switch) and not for any surrounding loop.
The same applies to continue IMHO.


这篇关于继续开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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