C ++与Python的实现

Tej*_*dey -2 c++ python loops

我的C ++正常运行,但是等效的Python代码挂在无限循环中。救命!

C ++

#include <iostream>

using namespace std;

int main()
{
    for(int i=0;i<4;++i){

        int j=0;

        while(i!=j){
            ++j;
            cout<<j<<endl;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

蟒蛇

for i in range(4):

    j = 0

    while i != j:

        ++j

        print(j)
Run Code Online (Sandbox Code Playgroud)

Joh*_*nck 5

++j在Python中不是问题。你要j += 1