Java do while loop making string testing act differently

后端 未结 3 1271
北荒
北荒 2020-12-20 10:34

I am very confused at the behavior of using the || operator on the .equals function. Is there a reason I can not use it on strings or something?

this works:

<
3条回答
  •  余生分开走
    2020-12-20 11:06

    Any Or condition works like this

    If first part if true, then second condition is not evaluated If first is false, then second is evaluated If either is true, the result is true.

    Now in your case, as input is Y, first condition is false but second is true. Hence the loop evaluates to true.

    The while loop will continue till you make the condition false. Hence it continues.

提交回复
热议问题