使用VBScript編程過程中我寫了很多的功能的誤差校驗碼功能開始前做動作。所以,如果一些預reqierements wan't滿足,那麼我願意「退出功能」。因此,例如:功能的多個出口點:這是一個好辦法嗎?
public fucnton func
if not condition then
func = -1
exit function
End If
'Other conditions with exit functions
'Then long code goes here
..........
..........
..........
func = res
End Function
因此,我可以從多個點中退出函數。這是一個好方法嗎?在這種情況下,我會得到的if語句
也許是更好的長期else分支寫:
public fucnton func
if not condition then
func = -1
Else
'Then long code goes here
..........
..........
..........
End If
End Function
請分享你的看法。