|
楼主 |
发表于 2009-12-10 12:05
|
显示全部楼层
原帖由 老伙计2008 于 2009-12-9 17:39 发表
boolenan减肥
x = x - (SomeVar > SomeOtherVar)
代码中的括号是不可缺少的[em07]
请测试
Private Sub ll()
    Dim a!, b!, c(2) As Byte, i%
    a = 1
    b = 1
    For i = 1 To 10
    c(0) = c(0)  ...
在这段代码中是不能省略,主要是因为逻辑运算符的优先级低于算术运算符。前面帖子中说的可获可以省略是特指那里所举的例子的。
你说的多重判断是这样么?
Private Sub test()
Dim a As Long , b As Long , c As Long , d As Long , i As Long
    t = Timer
    For i = 1 To 10000000
        a = 1
        b = 2
        c = 3
        d = 0
        If a <> b Then d = d + a
        If b < c Then d = d + b
        If c > a Then d = d + c
    Next
    Debug.Print Timer - t
    Debug.Print d
    t = Timer
    For i = 1 To 10000000
        a = 1
        b = 2
        c = 3
        d = 0
        d = d - (a <> b) * a - (b < c) * b - (c > a) * c  '次数少的情况下,这一句似乎比上面慢点。在数量大的时候稍微快一些
    Next
    Debug.Print Timer - t
    Debug.Print d
End Sub
[ 本帖最后由 Moneky 于 2009-12-10 12:14 编辑 ] |
|