--> 在 Java 中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29429605/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 15:15:29  来源:igfitidea点击:

What does --> means in Java?

javafor-loopsyntax

提问by TigerHix

for (int i = 99; i --> 0;) {
    System.out.println(i);
}

Above code works, and has the exactly same result of

上面的代码有效,并且具有完全相同的结果

for (int i = 99; i >= 0; i--) {
    System.out.println(i);
}

What does the syntax "-->" originally mean in Java? Since almost reachable search engines disallow special characters, I cannot seem to find the answer.

语法“-->”在Java中最初是什么意思?由于几乎可访问的搜索引擎不允许使用特殊字符,因此我似乎无法找到答案。

回答by shauryachats

-->is not a new operator.

-->不是新的运营商。

It is just a conjunctionof the operators --and >.

这仅仅是一个结合了运营商的-->

You first compare, and then decrement the variable.

您首先比较,然后递减变量。

That is,

那是,

i --> 0

becomes effectively

变得有效

i > 0; //Compare
i--; //and decrement

回答by Eran

i --> 0means i-- > 0, i is decrememnted and the previous value of iis compared to 0.

i --> 0意味着i-- > 0, i 被递减,并且之前的值与i进行比较0

回答by Rahul Tripathi

-->is not any operator. It is just the cocatenation of --and >.

-->不是任何运营商。它只是--and的串联>

So when you write

所以当你写

i-->0it means compare the value of iand then decrement it.

i-->0这意味着比较的值i然后递减它。

So for better readability it can be written as

所以为了更好的可读性,它可以写成

for (int i = 99; (i--)> 0;) {

回答by Mehmood Arbaz

notice here the increment/decrement place is not appeared. So it decrement iby 1 and compare it with 0.

注意这里没有出现递增/递减的地方。所以它减i1并与0比较。

The comparison check whether iis greater than 0 after the decrement performed.

i执行递减后比较检查是否大于0。

回答by silentprogrammer

i-- > 0

i-- > 0

i--is post decrement

i--后递减

>is greater than

>大于

for (initializatin; boolean expression;updation){
}

So you did initialization and but you checked boolean expression and updated in one step so it worked.

所以你做了初始化,但你检查了布尔表达式并一步更新,所以它起作用了。

回答by Prashant

there is no any operator -->its simply i-- > 0first it will do post decrements. then it will check condition and compare with 0whether its greater than are not.

没有任何运算符-->它只是i-- > 0首先它会做后减量。然后它会检查条件并比较它0是否大于。

Remember i's value will not be changed while comparison (i will be 1) after comparison it will decrements the value (i will now be 0) and print.

请记住,比较时 i 的值不会更改(i 将为 1),比较后它将递减值(i 现在为 0)并打印。