Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6128 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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

Posted

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.

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.