for循环,增加一倍 [英] for-loop, increment by double
本文介绍了for循环,增加一倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用for循环来解决我的问题,而不是在。可以执行以下操作:
I want to use the for loop for my problem, not while. Is it possible to do the following?:
for(double i = 0; i < 10.0; i+0.25)
我想添加双重值。
推荐答案
为了防止被浮点运算的工件所咬住,您可能需要使用一个整数循环变量,并在循环中导出所需的浮点值:
To prevent being bitten by artifacts of floating point arithmetic, you might want to use an integer loop variable and derive the floating point value you need inside your loop:
for (int n = 0; n <= 40; n++) {
double i = 0.25 * n;
// ...
}
这篇关于for循环,增加一倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文