Why '&&' and not '&'?

前端 未结 16 1538
别跟我提以往
别跟我提以往 2020-11-27 12:11

Why is && preferable to & and || preferable to |?

I asked someone who\'s been programming for years a

16条回答
  •  死守一世寂寞
    2020-11-27 12:53

    Simply,

    if exp1 && exp2

    if exp1 is flase don't check exp2

    but

    if exp1 & exp2

    if exp1 is false Or true check exp2

    and rarely people use & because they rarely want to check exp2 if exp1 is false

提交回复
热议问题