OrElse和AndAlso的运算符优先级 [英] Operator precedence with OrElse and AndAlso

查看:125
本文介绍了OrElse和AndAlso的运算符优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档

Visual Basic中的运算符优先级

AndAlso优先于OrElse.这是真的?让我们使用以下表达式:

AndAlso takes precedence over OrElse. Is this true? Let's take this expression:

Exp1 OrElse Exp2 AndAlso Exp3

Exp1 OrElse Exp2 AndAlso Exp3

文档告诉我,即使在Exp1为True的情况下,Exp2也会在任何情况下求值,这是因为AndAlso在运算符列表中位于OrElse之前.文档有误还是我读错了?

The documentation tells me that Exp2 is evaluated in any case even if Exp1 is True, just because AndAlso precedes OrElse in the list of operators. Is the documentation wrong or am I reading it wrong?

实际上,如果Exp1为True,则整个表达式为True,并且不对Exp2和Exp3求值.如果Exp1为False,则评估Exp2.如果Exp2为False,则整个表达式为False.如果Exp2为True,则将评估Exp3.

Actually, if Exp1 is True, the whole expression is True, and Exp2 and Exp3 are not evaluated. If Exp1 is False, Exp2 is evaluated. If Exp2 is False, the whole expression is False. If Exp2 is True, Exp3 is evaluated.

Armin

推荐答案

根据文档

Visual Basic中的运算符优先级

AndAlso优先于OrElse.这是真的?让我们使用以下表达式:

AndAlso takes precedence over OrElse. Is this true? Let's take this expression:

Exp1 OrElse Exp2 AndAlso Exp3

Exp1 OrElse Exp2 AndAlso Exp3

文档告诉我,即使在Exp1为True的情况下,Exp2也会在任何情况下求值,这是因为AndAlso在运算符列表中位于OrElse之前.文档有误还是我读错了?

The documentation tells me that Exp2 is evaluated in any case even if Exp1 is True, just because AndAlso precedes OrElse in the list of operators. Is the documentation wrong or am I reading it wrong?

实际上,如果Exp1为True,则整个表达式为True,并且不对Exp2和Exp3求值.如果Exp1为False,则评估Exp2.如果Exp2为False,则整个表达式为False.如果Exp2为True,则将评估Exp3.

Actually, if Exp1 is True, the whole expression is True, and Exp2 and Exp3 are not evaluated. If Exp1 is False, Exp2 is evaluated. If Exp2 is False, the whole expression is False. If Exp2 is True, Exp3 is evaluated.


这篇关于OrElse和AndAlso的运算符优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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