开发者

How do I transfer this c ++ for loop into java for loop

I am a newbie C++ and I want to convert this line of for loop code开发者_运维百科 into java version

for(;diff;diff++){
     do something here
}

diff is an integer type variable. Thanks in advance.


The issue is that C allows an implicit conversion from int to boolean for the termination condition whereas Java doesn't. Try

for(; diff != 0; diff++)
{

which should be equivalent.


In Java, unlike in C++, an integer is not automatically translated to a boolean expression. You have to write it like this in Java:

for ( ; diff != 0; diff++) {
    // do something here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜