c++循环在第一次运行后跳过
C++ Loop Skips After First Run
我有一段代码,在我的生命中我不明白为什么循环在第一次运行后跳过。
if (*itr2 != 0)
{
int s = *itr2;
//cout << s << endl;
k = k + s;
cout << "X: " << x << " K: " << k << " S: " << s << endl;
for (int i = x; i < s; i++)
{
cout << "test" << endl;
string value = allSub[i];
cout << value << endl;
vector<string>::iterator it2;
vector<string>::iterator it3;
it2 = find(subCode.begin(), subCode.end(), value);
int pos = distance (subCode.begin(), it2);
adMatrix [pos][pos] ++;
for (int v = 0; v < i; v++)
{
string value2 = allSub[v];
cout << "does it run: " << value2 << endl;
it3 = find(subCode.begin(), subCode.end(), value2);
int pos2 = distance (subCode.begin(), it3);
adMatrix [pos][pos2] ++;
adMatrix [pos2][pos] ++;
}
x = i;
}
x++;
}
假设x和k初始化为0。输出如下:
X: 0 K: 4 S: 4
test
CSCI203
test
CSCI235
does it run: CSCI203
test
CSCI222
does it run: CSCI203
does it run: CSCI235
test
CSCI205
does it run: CSCI203
does it run: CSCI235
does it run: CSCI222
X: 4 K: 7 S: 3
X: 5 K: 11 S: 4
X: 6 K: 13 S: 2
X: 7 K: 17 S: 4
为什么x = 4之后的值不运行for循环?
for(int i = x; i < s; i++) {
检查后面的迭代:s小于x,因此初始化i大于s,并且循环永远不会执行。
相关文章:
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 为什么无论你输入什么,这"while(cin.get(str,3))"只运行一次?
- 花括号使循环运行一次?
- 我必须构建我的项目 2 次,第一次失败,因为它无法打开库
- 是什么导致我的循环在第一次迭代中运行得更慢
- QLibrary 函数在第一次调用时工作缓慢
- 第一次运行时,用CL挂起的代码挂太长
- cl 生成的可执行文件在第一次运行时运行速度非常慢
- 丢失的数据包仅在第一次运行中发生
- 第一次运行程序时出现损坏的双链表错误,后续运行正常
- Visual C++Express.exe在第一次执行之后再次运行
- C++-在第一次运行后跳过代码
- 如何在第一次运行循环时忽略代码的特定部分
- 程序在第一次运行时正确地找到了最大值和最小值,但如果我再次运行,它会给我错误的答案
- c++使用一个函数表示多个变量.只有第一次运行有效
- 第一次运行后,反向编号功能无法正常工作
- 一种测试您是否第一次运行多个递归调用 C++ 的方法
- Qt在运行时改变对话框的模式,而不是第一次隐藏它,然后再显示
- c++循环在第一次运行后跳过
- dev c++第一次编译但没有运行(BLACKSCREEN)