if statement not working right?

前端 未结 5 1655
执念已碎
执念已碎 2020-12-02 03:19

I\'ve looked and looked with the debugger and cannot seem to figure out why the IF statement always prints the message.

The IF statement checks to see if yesno != \'

5条回答
  •  爱一瞬间的悲伤
    2020-12-02 03:32

    you cannot OR an expression (yesno!='Y') and a statement ("N") which is also an expression. its only two or more expressions that can be combined using || and && to get the required output.

    if(yesno!="Y"||"N")
    

    is actually

    if(yesno!="Y" || TRUE)
    

    which is always true because:

    Exp||TRUE=TRUE 
    

    regardless of the expression.

    use if(yesno!="Y"|| yesno!="N")      // and in this case its && and not || i think
    

提交回复
热议问题