for 循环,加倍 [英] for-loop, increment by double
本文介绍了for 循环,加倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对我的问题使用 for 循环,而不是 while.是否可以执行以下操作?:
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屋!
查看全文