Sign in to follow this  
Followers 0
mbunds

Difference between Switch and Select?

5 posts in this topic

I have searched the forums for an answer to this with no luck. What is the functional difference between the "Switch" and the "Select" keywords for responding to Case, and when would a programmer choose to use one over the other?

Share this post


Link to post
Share on other sites



I have searched the forums for an answer to this with no luck. What is the functional difference between the "Switch" and the "Select" keywords for responding to Case, and when would a programmer choose to use one over the other?

Switch is for when all the cases are based on a single value (the one passed on the same line with the Switch keyword). All the Case statements (like "Case 1" or "Case > 10") are in reference to that one value.

Select can use completely unrelated statements for each case (like "Case $n = 1" and "Case $x > 10")

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

With Switch you only have to define the expression once. With Select you have to do it every Case.

And as far as I can see, only Switch can do $var TO $var2

<value> To <value> The case is executed if the expression is between the two values.

But then again only Select, accouring to the help, seems the be the only one able to do:

The expression can contain the boolean operators of AND, OR, and NOT as well as the logical operators <, <=, >, >=, =, ==, and <> grouped with parentheses as needed.

Edit: Darn, If I hadn't push 'back' by accident I had beaten PsaltyDS... ^^

Edited by Triblade

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share this post


Link to post
Share on other sites

Switch is for when all the cases are based on a single value (the one passed on the same line with the Switch keyword). All the Case statements (like "Case 1" or "Case > 10") are in reference to that one value.

Select can use completely unrelated statements for each case (like "Case $n = 1" and "Case $x > 10")

;)

Thank you kindly for the quick and concise answer!

Share this post


Link to post
Share on other sites

Edit: Darn, If I hadn't push 'back' by accident I had beaten PsaltyDS... ^^

BWAAAHAHAHAHA! ;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0