没有“继续”换? [英] There is no "continue" for switch?

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

问题描述

如果我想要以下内容怎么办?


vector< intv;


// v由push_back()


开关(v.size()){

案例2:

//做点什么


案例4:

//以某种方式删除两个元素

//然后执行与案例2相同的事情


案例6:

//以某种方式删除两个元素

//然后执行与案例4相同的事情


默认值:

// ...

}

我以为使用继续实现这一点,但得到了这个:


继续声明不在循环内

What if I want the following:

vector<intv;

// v is loaded by push_back()

switch( v.size() ) {
case 2:
//do something

case 4:
//somehow delete two element
//and then do the same thing as in case 2

case 6:
//somehow delete two element
//and then do the same thing as in case 4

default:
//...
}
I thought using "continue" to implement this but got this:

continue statement not within a loop

推荐答案

在文章< 7864a589-19a7-458d-99cd-
26 ******* ***@x41g2000hsb.googlegroups.com >, zh ********* @ gmail.com

说...
In article <7864a589-19a7-458d-99cd-
26**********@x41g2000hsb.googlegroups.com>, zh*********@gmail.com
says...

如果我需要以下内容怎么办:


vector< intv;


// v由push_back加载()


switch(v.size()){

案例2:

//做点什么


案例4:

//不知何故删除两个元素

//然后做与案例2相同的事情


案例6:

//不知何故删除两个元素

//然后做与案例4相同的事情


默认值:

//...

}
What if I want the following:

vector<intv;

// v is loaded by push_back()

switch( v.size() ) {
case 2:
//do something

case 4:
//somehow delete two element
//and then do the same thing as in case 2

case 6:
//somehow delete two element
//and then do the same thing as in case 4

default:
//...
}



正确 - 继续工作循环不是sw痒。幸运的是你

不需要任何相当困难的东西:


switch(v.size()){

case 6:

//不知何故删除两个元素(原文如此)

案例4:

//不知何故删除两个元素

案例2:

//做点什么

}


如果在结束时没有休息块,执行将流入

到下一个区块......


-

后来,

杰瑞。


宇宙是自己想象的虚构。

Correct -- continue works for loops by not switches. Fortunately you
don''t need anything quite that difficult:

switch (v.size()) {
case 6:
// somehow delete two element (sic)
case 4:
// somehow delete two element
case 2:
// do something
}

If there isn''t a break at the end of a block, execution will flow
through to the next block...

--
Later,
Jerry.

The universe is a figment of its own imagination.


On 3 ??18è?,? ???11ê±46·?,xz< zhang.xi ... @ gmail.com>写道:
On 3??18è?, ????11ê±46·?, xz <zhang.xi...@gmail.com>wrote:

如果我想要以下内容怎么办? />

vector< intv;


// v由push_back加载()


switch(v .size()){

案例2:

//做点什么


案例4:

//以某种方式删除两个元素

//然后做同样的瘦g和案例2一样


案例6:

//不知何故删除两个元素

//然后做同样的事情如案例4


默认值:

// ...


}


我以为使用继续实现这个但得到了这个:


继续声明不在循环中
What if I want the following:

vector<intv;

// v is loaded by push_back()

switch( v.size() ) {
case 2:
//do something

case 4:
//somehow delete two element
//and then do the same thing as in case 2

case 6:
//somehow delete two element
//and then do the same thing as in case 4

default:
//...

}

I thought using "continue" to implement this but got this:

continue statement not within a loop



请详细说明你的意图。

please detail your intent.


3月18日上午10点57分,Jerry Coffin< jcof ... @ taeus.comwrote:
On Mar 18, 10:57 am, Jerry Coffin <jcof...@taeus.comwrote:

In文章< 7864a589-19a7-458d-99cd-

2611d772e ... @ x41g2000hsb.googlegroups.com> ;, zhang.xi ... @ gmail.com

说...
In article <7864a589-19a7-458d-99cd-
2611d772e...@x41g2000hsb.googlegroups.com>, zhang.xi...@gmail.com
says...

如果我需要以下内容怎么办:
What if I want the following:


vector< intv;
vector<intv;


// v由push_back加载()
// v is loaded by push_back()


switch (v.size()){

案例2:

//做点什么
switch( v.size() ) {
case 2:
//do something


案例4:

//以某种方式删除两个元素

//然后执行与案例2相同的事情
case 4:
//somehow delete two element
//and then do the same thing as in case 2


案例6:

//以某种方式删除两个元素

//然后执行与案例4相同的事情
case 6:
//somehow delete two element
//and then do the same thing as in case 4


默认值:

// ...

}
default:
//...
}



正确 - 继续通过非开关工作循环。幸运的是你

不需要任何相当困难的东西:


switch(v.size()){

case 6:

//不知何故删除两个元素(原文如此)

案例4:

//不知何故删除两个元素

案例2:

//做点什么


}


如果没有休息一个区块的结束,执行将流入

到下一个区块......


Correct -- continue works for loops by not switches. Fortunately you
don''t need anything quite that difficult:

switch (v.size()) {
case 6:
// somehow delete two element (sic)
case 4:
// somehow delete two element
case 2:
// do something

}

If there isn''t a break at the end of a block, execution will flow
through to the next block...



好​​吧,我给了一个不那么强硬的案例,如果案件有点困难怎么办?


vector< intv;


// v由push_back加载()


开关(v.size()){

案例2:

//做点什么


案例4:

//以某种方式删除两个元素

//然后执行与案例2相同的事情


案例6:

//以某种方式删除*四*元素

//然后执行与c相同的操作ase 2


默认:

// ...


}


即我在处理案例4和案例6之后都要去案例2.

well, I gave a case not so tough, what if a case a little tougher?

vector<intv;

// v is loaded by push_back()

switch( v.size() ) {
case 2:
//do something

case 4:
//somehow delete two element
//and then do the same thing as in case 2

case 6:
//somehow delete *four* element
//and then do the same thing as in case 2

default:
//...

}

i.e. I want to go to case 2 both after I treat the case 4 and case 6.


>

-

后来,

杰里。


宇宙是自己想象的虚构。
>
--
Later,
Jerry.

The universe is a figment of its own imagination.


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

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