gaby78 Posted February 14, 2008 Posted February 14, 2008 Could someone tell me if it is better to use a series of If...End If or a series of Else If. Expl: what’s better: Script1 or Script2 Script1 IF [Amount = 100] Do 1 End IF IF [Amount = 200] Do 2 End IF IF [Amount = 300] Do 3 End IF Script2 IF [Amount = 100] Do 1 ELSE IF [Amount = 200] Do 2 ELSE IF [Amount = 300] Do 3 End IF Thanks
Colin Keefe Posted February 14, 2008 Posted February 14, 2008 They behave differently, and depending on context one or the other might be best. In the first example, the subsequent If [] End If [] blocks will still evaluate regardless of whether the first returns true. Which might be what you want if "Do 1" were to add some number to Amount that you want to perform further evaluations on. In this particular case it won't, but it's important to make the distinction. If [] Else If [] Else [] End If []is useful when only one If [] block should be executed.
Fitch Posted February 14, 2008 Posted February 14, 2008 In your example, the second one is better, because in the first script it has to evaluate the 2nd and 3rd IF, whereas in the second script there's no wasted evaluation. However, if the first script looked like the following, then I'd say there's no real difference: IF [Amount = 100] Do 1 Exit Script End IF IF [Amount = 200] Do 2 Exit Script End IF IF [Amount = 300] Do 3 Exit Script End IF
gaby78 Posted February 14, 2008 Author Posted February 14, 2008 Thanks guys; it see the difference now.
Recommended Posts
This topic is 6128 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now