i ++&之间有什么区别? ++ i在for循环中? [英] What is the difference between i++ & ++i in a for loop?
本文介绍了i ++&之间有什么区别? ++ i在for循环中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚开始学习Java,现在我进入了for循环语句.我不明白++i
和i++
在for循环中如何工作.
I've just started learning Java and now I'm into for loop statements. I don't understand how ++i
and i++
works in a for-loop.
它们如何在加减运算等数学运算中起作用?
How do they work in mathematics operations like addition and subtraction?
推荐答案
它们都增加数字. ++i
等同于i = i + 1
.
They both increment the number. ++i
is equivalent to i = i + 1
.
i++
和++i
非常相似,但不完全相同.两者都会增加数字,但是++i
会增加对当前表达式求值之前的数字,而i++
会增加对表达式求值之后的数字.
i++
and ++i
are very similar but not exactly the same. Both increment the number, but ++i
increments the number before the current expression is evaluted, whereas i++
increments the number after the expression is evaluated.
int i = 3;
int a = i++; // a = 3, i = 4
int b = ++a; // b = 4, a = 4
这篇关于i ++&之间有什么区别? ++ i在for循环中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文