Jump to content

Recommended Posts

Posted

Right now I have 7 elseif starements like this:

If X Then
     ...
ElseIf Y Then
     ...
ElseIf Z Then
.
.
.
Else
     ...

Would it be faster if I used a Select Case instead? When using elseif, does it check each elseif, or once a condition is satisfied it doesn't check the others?

Posted

From the helpfile:

If...ElseIf...Else...EndIf : If the expression is true, the first statement block is executed. If not, the first true ElseIf block is executed. Otherwise, the "Else" block is executed.

Select...Case...EndSelect : If the expression is true the following statements up to the next Case or EndSelect statement are executed. If more than one of the Case statements are true, only the first one is executed.

Posted

From the helpfile:

If...ElseIf...Else...EndIf : If the expression is true, the first statement block is executed. If not, the first true ElseIf block is executed. Otherwise, the "Else" block is executed.

Select...Case...EndSelect : If the expression is true the following statements up to the next Case or EndSelect statement are executed. If more than one of the Case statements are true, only the first one is executed.

<{POST_SNAPBACK}>

run this to see it for yourself

$i = 3

select 
case $i > 1
    MsgBox(0,"case","first")
case $i > 2
    MsgBox(0,"case","second")
EndSelect
Posted

run this to see it for yourself

$i = 3

select 
case $i > 1
    MsgBox(0,"case","first")
case $i > 2
    MsgBox(0,"case","second")
EndSelect

<{POST_SNAPBACK}>

Yeah, the second case isn't executed.

I pointed the difference of both here, according to the documentation.

Posted

And to add to that, if you DO want it to check each If statement, you'd actually have to have a seperate If..EndIf statement for each check.

Something like the following:

$i = 3

If $i > 1 Then
    MsgBox(0,"case","first")
EndIf
If $i > 2 Then
    MsgBox(0,"case","second")
EndIf
Posted

Yeah, the second case isn't executed.

I pointed the difference of both here, according to the documentation.

<{POST_SNAPBACK}>

yes, your explanation was right on, and probably didn't need any further elaboration, and i didn't mean to imply otherwise. i just like to give a practical example when possible... old habits die hard...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...