跳过当前' for '迭代的其余部分,开始一个新的迭代
C++ Skipping the rest of the current `for` iteration and beginning a new one.
考虑下面的c++代码
for(int i=0; i<=N; ++i)
{
if(/* Some condition 1 */) {/*Blah Blah*/}
if(/* Some condition 2 */){/*Yadda Yadda*/}
}
是否存在关键字/命令,以便如果条件1的计算结果为true
并且执行/*Blah Blah*/
,我可以跳过当前迭代的其余部分,并通过增加i
开始新的迭代。
我知道最接近这种语句跳过的是break
,但它完全终止了循环。
我想可以通过使用一些标志和if语句来做到这一点,但是一个简单的关键字将非常有帮助。
使用关键字continue
,它将'继续'到下一次循环。
这种情况似乎更适合if. else..而不是continue,尽管continue也可以。
for(int i=0; i<=N; ++i)
{
if(/* Some condition 1 */)
{/*Blah Blah*/}
else if(/* Some condition 2 */)
{/*Yadda Yadda*/}
}
使用Continue
语句,停止当前循环并继续下一个循环,而不是完全中断
相关文章:
- 列表的有效性在插入后开始迭代器
- 如何创建一个循环,该循环检查每次迭代并在每次迭代后从头开始
- 如何将迭代器(包括结束和开始之前的迭代器)测试到列表或forward_list保持有效
- 为什么 std::variant 使用开始和结束迭代器进行编译?
- Qi::p arse Boost Change开始迭代器
- 从两端开始浏览列表,然后使用迭代器在中间停止
- ->第一个/第二个到空映射迭代器开始
- 如何使用迭代器实现从序列的中间到开始的循环
- 向量模板类:擦除(迭代器开始,迭代器端)
- 如何创建从开始和结束迭代器的范围
- 字符串文本的C++宏开始迭代器和结束迭代器
- Vector::迭代器在与开始比较时崩溃
- map/set迭代器不可递增,我无法从头开始重新启动映射
- 从任何位置开始迭代整个数组,仅使用一个变量
- 如何从结束到开始迭代unordered_set
- 开始,结束简单类的迭代器规范
- 如何返回提升multi_index迭代器的开始和结束
- 使用模板<类输入迭代器>字符串(输入迭代器开始,输入迭代器结束)时出现奇怪的错误;
- C++映射从迭代器位置开始搜索
- 减法或递减随机访问迭代器指向开始