February 14, 200818 yr 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
February 14, 200818 yr 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.
February 14, 200818 yr 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
Create an account or sign in to comment