Why would a language NOT use Short-circuit evaluation?

后端 未结 18 1932
天涯浪人
天涯浪人 2020-12-03 09:42

Why would a language NOT use Short-circuit evaluation? Are there any benefits of not using it?

I see that it could lead to some performances issues... is that true?

18条回答
  •  抹茶落季
    2020-12-03 10:22

    If you wanted the right hand side to be evaluated:

    if( x < 13 | ++y > 10 )
        printf("do something\n");
    

    Perhaps you wanted y to be incremented whether or not x < 13. A good argument against doing this, however, is that creating conditions without side effects is usually better programming practice.

提交回复
热议问题