布尔表达式-操作顺序 [英] Boolean Expression - Order of Operations

查看:94
本文介绍了布尔表达式-操作顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Excel VBA中进行了测试:

I have a test in Excel VBA:


If (test1) And (test2) And (test3) Then
    'do something
End If

在C,Java等环境中,首先运行test1,然后运行test2,然后运行test3.至关重要的是,如果test1为false,则整个测试为false,因此其余测试不会运行.

In C, Java, etc. test1 would be run first, then test2, then test3. Critically, if test1 is false the whole test is false so the remaining tests do not run.

在这种情况下,使用VBA是否会发生这种情况?如果是这样,测试按什么顺序运行?

Does that happen in this case with VBA? If so, in which order are the tests running?

推荐答案

.NET之前的所有VB中都没有短路之类的东西.即使不需要,也会对所有表达式求值.如果您想短期学习,请嵌套IF.

In all VBs prior to .NET there is no such thing as short-circuit. All expressions will be evaluated even if not required. If you want short-curcuit, do nested IFs.

这篇关于布尔表达式-操作顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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