如果别的 ... [英] if else ...

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

问题描述

我如何在If语句中使用或者?


例如。 if(x> 10或y> 10)

{

....

}


Hrcko

How can I use in If statement Or?

for example. if (x>10 or y>10)
{
....
}

Hrcko

推荐答案

你的意思是


if(x> 10 || y> 10)

{

}


Glenn

" Hrvoje Voda" < HR ********* @ luatech.com>在消息中写道

news:cu ********** @ ls219.htnet.hr ...
Do you mean

if ( x > 10 || y > 10 )
{
}

Glenn
"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:cu**********@ls219.htnet.hr...
如何在If语句中使用或?

例如。 if(x> 10或y> 10)
{
....
}

Hrcko
How can I use in If statement Or?

for example. if (x>10 or y>10)
{
....
}

Hrcko



" Hrvoje Voda" < HR ********* @ luatech.com>写道:
"Hrvoje Voda" <hr*********@luatech.com> wrote:
我如何在If语句或?
中使用。如果(x> 10或y> 10)
How can I use in If statement Or?
for example. if (x>10 or y>10)




if(x> 10 || y> 10)//或


if(x> 10& y> 10)//和


P.



if (x > 10 || y > 10) // or

if (x > 10 && y > 10) // and

P.


保罗·柯林斯 <音响****************** @ CL4.org>在消息中写道

news:cu ********** @ titan.btinternet.com ...
"Paul E Collins" <fi******************@CL4.org> wrote in message
news:cu**********@titan.btinternet.com...
" Hrvoje Voda" < HR ********* @ luatech.com>写道:
"Hrvoje Voda" <hr*********@luatech.com> wrote:
我如何在If语句或?
中使用。 if(x> 10或y> 10)
How can I use in If statement Or?
for example. if (x>10 or y>10)



if(x> 10 || y> 10)//或

if(x> ; 10&& y> 10)//和

P.



if (x > 10 || y > 10) // or

if (x > 10 && y > 10) // and

P.




值得一提的是-circuiting条件语句

以上。


if(x> 10 | y> 10)在这种情况下可以正常工作。


使用||它是短路有条件的,即它将评估x>

10并且只有当这是假的时候,y>将对10进行评估。


类似于if(x> 10&& y> 10),x> 10将被评估,并且只有当
为真时,y> 10将被评估。


在提到的情况下,它没有什么区别,但在做

时要小心:


(1)if(++ x> 10 || ++ y> 10)


而不是

(2)if(++ x> 10 | ++ y> 10)


In(1)++ y仅在++时执行x大于10,但在(2)中将执行
++ x和++ y.


我不要混淆这个问题,但我认为保持这一点非常重要。



It might be worth mentioning short-circuiting for the conditional statements
above.

if (x > 10 | y > 10) will work fine in this case.

by using || it "short-circuits" the conditional, i.e. it will evaluate x >
10 and only if this is false, y > 10 will be evaluated.

Similarly in if(x > 10 && y > 10), x > 10 will be evaluated and only if tihs
is true, y > 10 will be evaluated.

In the case mentioned it won''t make a difference, but be careful when doing
something like:

(1) if (++x > 10 || ++y > 10)

as opposed to

(2) if (++x > 10 | ++y > 10)

In (1) ++y will only be execute if ++x is greater than 10, but in (2) both
++x and ++y will be executed.

I don''t to confuse the issue, but I do think it''s important to keep this in
mind.


这篇关于如果别的 ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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