查看for循环计数器是否已增加 [英] See if a for loop's counter has increased

查看:86
本文介绍了查看for循环计数器是否已增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个for循环,我有一个if语句,将检查计数器是否增加。我该怎么检查?



下面我举了一个例子,说明了我的想法。感谢您提前的帮助。



我尝试过:



 for(int i = 0; i< 8; i ++){
if(** counter'i'has ** **){
// do stuff
}
}

解决方案

在循环外添加变量,并将其设置为零。

在循环内部,将其与 i 的当前值进行比较。如果不同, i 已更改。

在循环的底部,将其设置为 i

I have a for loop and I have an if statement that will check if the counter increases. How would I check that?

Below I have given an example of what I had in mind. Thanks for your help in advance.

What I have tried:

for (int i = 0; i < 8; i++){
   if ( **counter 'i' has increased** ){
      //do stuff
   }
}

解决方案

Add a variable outside the loop, and set it ti zero.
Inside the loop, compare it to the current value of i. If it is different, i has changed.
At the bottom of the loop, set it to i


这篇关于查看for循环计数器是否已增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆