考虑一下这个C++代码
for(int i=0; i<=N; ++i)
{
if(/* Some condition 1 */) {/*Blah Blah*/}
if(/* Some condition 2 */){/*Yadda Yadda*/}
}
Run Code Online (Sandbox Code Playgroud)
是否有任何关键字/命令,以便如果条件1求值true并且/*Blah Blah*/I的执行可以跳过当前迭代的其余部分并通过递增开始新的迭代i.
我对这种语句跳过最接近的事情就是break完全终止循环.
我想通过使用一些标志和if语句可以做到这一点,但一个简单的关键字将非常有用.
这种情况似乎更适合 if.. else .. 而不是 continue,尽管 continue 也可以正常工作。
for(int i=0; i<=N; ++i)
{
if(/* Some condition 1 */)
{/*Blah Blah*/}
else if(/* Some condition 2 */)
{/*Yadda Yadda*/}
}
Run Code Online (Sandbox Code Playgroud)