c++ - 包含两个整数的代码如何逐步操作 C++?
问题描述
我对 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;
}
希望我很清楚!
推荐阅读
- google-apps-script - 如何使用应用程序脚本获取有权访问 Google 共享驱动器的所有用户的列表
- java - 如何使用 dynamodb 中的复合主键中的分区键获取记录
- python - How to extract the text present in cookie pop up box using python?
- python - 将 isPrime() Python 转换为 Haskell
- django - 如何在 django rest 框架 API 中使 ImageField 成为可选
- spring-boot - 使用 JPA 审计的 Autowired Repository 为空
- sql - 在oracle数据库的sql视图中使用sum函数
- c# - 如何从有条件的数据库中随机获取数据?
- android - 如何再次调用 LiveData
- c++ - 使用 std::cin 时,我的 C++ 代码出现分段错误