开发者

Does VB6 short-circuit complex conditions?

开发者 https://www.devze.com 2023-01-21 02:18 出处:网络
Does VB6 short circuit conditional tests? That is to say, can I be sure a statement like... If index <= array_si开发者_运维技巧ze And array(index) > something Then

Does VB6 short circuit conditional tests? That is to say, can I be sure a statement like...

If index <= array_si开发者_运维技巧ze And array(index) > something Then

will never burst the array, whatever the value of index might happen to be?


No, VB6's And and Or don't short-circuit (which is the reason why the short-circuit versions are called AndAlso and OrElse in VB.net — backward compatibility).


In addition to the If/Then/Else/End If block, VB6 also supports a single-line If/Then/Else construct. You can nest these to achieve simple short-circuiting. However, since it's a single-line statement, you must perform your desired action on the same line as well. For example:

' From (no short-circuit)
If index <= array_size And array(index) > something Then

' To (short-circuit)
If index <= array_size Then If array(index) > something Then ...


Select Case is a short circuit method if you can use it for your purpose.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号