java --i 和 i-- 和有什么不一样?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16776726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between --i and i--?
提问by jbduzan
In some code i've seen a for loop with a --i as third parameters
在某些代码中,我看到了一个 for 循环,其中一个 --i 作为第三个参数
for(int i=array.length; i<0; --i)
Maybe someone can explain me the difference with i-- ?
也许有人可以解释我与 i-- 的区别?
i guess it's something like the moment when i is decremented ?
我想这就像我递减的那一刻?
回答by Francis.Beauchamp
If, for example, i = 5
:
例如,如果i = 5
:
--i
decrements i by 1 then gives you the value of i (4).
--i
将 i 减 1,然后为您提供 i (4)的值。
i--
gives you the value of i (5)then decrements it by 1.
i--
为您提供 i (5)的值,然后将其减 1。
Both will give you the same result in a for loop.
两者都会在 for 循环中为您提供相同的结果。