||和&& [英] || and &&

查看:97
本文介绍了||和&&的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没有完全掌握(很多事情)的一件事就是

使用,例如


if(c!= b || c!= e || c!= f).... etc


vs.


if((c!= b&& c!= e&& c!= f)


这些之间真正的实际区别是什么,如果不是这样的话?

a这个问题的好例子,有人可能会给出一个更好的例子和解释。


提前谢谢。

One of the things I have yet to fully grasp ( of many things) is when
to use, for example

if (c !=b || c !=e || c !=f)....etc

versus

if ( (c !=b && c !=e && c !=f)

What is the real practical difference between these, and if this is not
a good example of the problem, could someone perhaps give a better
example and explanation.

Thanks in advance.

推荐答案



mdh写道:

mdh wrote:

我有一件事尚未完全掌握(很多事情)是什么时候使用

,例如


if(c!= b || c!= e || c!= f)....等


vs.


if((c!= b&& c!= e && c!= f)


这些之间真正的实际区别是什么,如果不是这个问题的好例子,那么或许某人可能会给出一个更好的例子和解释。
One of the things I have yet to fully grasp ( of many things) is when
to use, for example

if (c !=b || c !=e || c !=f)....etc

versus

if ( (c !=b && c !=e && c !=f)

What is the real practical difference between these, and if this is not
a good example of the problem, could someone perhaps give a better
example and explanation.



使用&&当所有条件都必须为真时。

使用||任何条件都可以是真的。


if(criminal_is_caught&& criminal_is_convicted){

send_to_jail();

}


if(criminal_is_electrocuted || criminal_dies_of_old_age){

order_coffin();

}


mdh写道:
mdh wrote:

我还没有完全掌握的事情之一(很多事情)是什么时候/>
使用,例如


if(c!= b || c!= e || c!= f).... etc
One of the things I have yet to fully grasp ( of many things) is when
to use, for example

if (c !=b || c !=e || c !=f)....etc



使这个假的唯一条件是当所有三个表达式

都为假时。

The only condition that makes this false, is when all three expressions
are false.


vs.


if((c!= b&& c!= e&& c!= f)
versus

if ( (c !=b && c !=e && c !=f)



实现这一点的唯一条件是当所有三个表达式

都为真时。

The only condition that makes this true, is when all three expressions
are true.



< a href =mailto:dc ***** @ connx.com> dc ***** @ connx.com e:

mdh写道:
mdh wrote:

我还没有完全掌握的一件事(很多)是什么时候使用

,例如


if(c!= b || c!= e || c!= f)....等


vs.


if((c!= b&& c!= e && c!= f)


这些之间真正的实际区别是什么,如果不是这个问题的好例子,可以有人可能会给出更好的

示例和解释。
One of the things I have yet to fully grasp ( of many things) is when
to use, for example

if (c !=b || c !=e || c !=f)....etc

versus

if ( (c !=b && c !=e && c !=f)

What is the real practical difference between these, and if this is not
a good example of the problem, could someone perhaps give a better
example and explanation.



当所有条件必须为真时,请使用&&。 >
当任何条件成立时使用||。


if(criminal_is_caught&& criminal_is_convicted){

send_to_jail() ;

}


if(criminal_is_electrocuted || criminal_dies_of_old_age){

order_coffin();

}


Use && when all of the conditions must be true.
Use || when any of the conditions can be true.

if (criminal_is_caught && criminal_is_convicted) {
send_to_jail();
}

if (criminal_is_electrocuted || criminal_dies_of_old_age) {
order_coffin();
}



tks ...是的...如果负面不存在,那就有意义......''!''

对我来说似乎很混乱。

tks...yes...if the negative is not present, that makes sense....the ''!''
seems to muddy the waters for me.


这篇关于||和&amp;&amp;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆