PB代码优化(3)


// 方式二

ll_start = Cpu()

for i = 1 to 900000

if 1 > 1 Then

else

i = i

end if

Next

ll_used2 = Cpu() - ll_start

// 查看结果

If ll_used2 > ll_used1 Then

MessageBox( " 提示 " , " 前者运行时间短! " )

Else

MessageBox( " 提示 " , " 后者运行时间短! " )

End If

可能有人会说,用下面的那种方式,如果在条件表达式返回 false 的时候,那么, if 下就没有代码,这样看起来就不太舒服。的确是这样。因此,我们在写成上面的那种方式时,尽量保持不要使用 not 运算,而保持条件表达式本身就返回希望的 true 值。

第三种情况:

IF condition1 THEN

//condition1

ELSEIF condition2 THEN

//condition2

ELSEIF condition3 THEN

//condition3

ELSE

//Other

END IF

choose case /expression/

case /item/

/statementblock/

case /item/

/statementblock/

case else

/statementblock/

end choose

对于形如这样的表达式,我想我们一般都没去考虑先后顺序。但是,其实我们应该把最可能发生的情况,放在前面,这样可以避免在对一大堆条件进行判断后,才到我们真正需要运行代码的地方。

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus