为什么这个do while循环会无限执行呢?

Why is this do while loop infinitely executing?

为什么这个do while循环会无限执行?

#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
unsigned int base;
cout << "Base: ";
cin >> base;
for (int i = 1; i <= base; i++) {
    int j = 0;
    do {
        cout << "#";
        j++;
    } while (j = i);
    cout << endl;
};
system("pause");
// keep on building up until you reach 'base'
return 0;
}

我真的很困惑。这个程序应该像这样创建一个三角形

#
##
###

(用户输入底数,所以在本例中底数 = 3) 有人帮我改正菜鸟的错误吗?

你可能想试试 while (j == i);

j = i 是一个变量 declaration/assignment 只要它成功就永远为真。似乎您想比较两者,所以使用 等于运算符: ==.

编辑: 打错了,因此出现了与您的问题相同的错误。修正了那个。