Arrrghmatey Posted July 25, 2005 Share Posted July 25, 2005 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? Link to comment Share on other sites More sharing options...
Josbe Posted July 25, 2005 Share Posted July 25, 2005 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. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
seandisanti Posted July 25, 2005 Share Posted July 25, 2005 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 Link to comment Share on other sites More sharing options...
Josbe Posted July 25, 2005 Share Posted July 25, 2005 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. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
therks Posted July 25, 2005 Share Posted July 25, 2005 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 My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
seandisanti Posted July 25, 2005 Share Posted July 25, 2005 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... Link to comment Share on other sites More sharing options...
Recommended Posts
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