Getting confused with == and = in “if” statement

前端 未结 5 471
时光说笑
时光说笑 2020-12-18 23:06

I know that we cant use assignment operator in if statements in java as we use in any other few languages.

that is

            int a;

            i         


        
5条回答
  •  粉色の甜心
    2020-12-18 23:34

    The reason the second code works okay is because it is assigning 'b' the value of true, and then comparing to see if b is true or false. The reason you can do this is because you can do assignment operators inside an if statement, AND you can compare against a boolean by itself. It would be the same as doing if(true).

提交回复
热议问题