c++ - C++包含两个整数的代码如何逐步运行?

标签 c++ while-loop

我是C++编程的新手,我在python中回顾了while循环,但是在这里这两个整数使我感到困惑。如果您能向我解释这个while循环如何逐步运行,我将非常高兴。

#include<iostream>
using namespace std;
int main() {
    int i;
    int j; 
    while(i<10 || j < 5) { // i kucuk ondan kucuk oldu surece {} icerisindeki islemler surekli olarak while() loopu ile tekrarlancak 
        cout<<"i: "<<i<<" "<<"j: "<<j<<endl;
        i = i + 1;  // eger bu kod olmaz ise, sonsuza dek i degerine basacak
        j = j + 1;
    }
    return 0;
}

最佳答案

#include<iostream>
using namespace std;
int main() {
/* You should first give a starting value
 to the I and j, otherwise they 
 will get a random number and your while won't work*/ 
    int i=0; 
    int j=0;
/* so as the word says "while" - while (something here is true)do the 
following code between the starting 
brackets and the finishing brackets. When it's not True skip the loop and go to the next line, in this example we will go to return 0 */ 

/*The value of i is 0 and the value of j is 0, and we first check if 0(i)<10 that's true next we check the other one 
if 0(j) < 5 yes do the following block*/
/* the || mean "or' if either one of them 
is true do the following block of code between the brackets*/

    while(i<10 || j < 5) {
        //we print
        cout<<"i: "<<i<<" "<<"j: "<<j<<endl;
        //we are incrementing the values of i and j for 1;
        i = i + 1;  
        j = j + 1;

        /*so what happens now it jumps again to the while
          and checks if the statement is true, now i = 1 and j = 1; 
          and this runs until i is 10 because only then the i won't be lesser then 
          10 and j won't be lesser then 5 it will be false*/ 
       */

    }
    //close the program
    return 0;
}

希望我很清楚!

关于c++ - C++包含两个整数的代码如何逐步运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61667473/

相关文章:

c++ - 检测类型是否为关联容器

c++ - Poco C++ SAX 解析器 : how to get element "inner text"?

c++ - 用 std::addressof 存储指针地址

java - 需要帮助修改输入验证和错误消息的代码

c - 在 C 中帮助 While 循环

c++ - 我怎样才能使这个 "while"工作?

c++ - 多文件项目中的全局函数?

c++ - 如何完全清除Windows C++中的所有用户环境变量

c - 循环遍历文件并在 C 中打印文件属性

Java 不大于或等于 Char 类型的运算符