Sign in to follow this  
Followers 0
emmanuel

Select Or If?

4 posts in this topic

so, people say that select is better for some things, and If better for others... Which is better for what? (I guess that's the short version of the question)


"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites



It's mostly a personal thing. Anything more than 3 "if" or "elseif" choices and I would use Select. But then other devs would use elseif for many more. :D

The basic rule would be "for a few choice" use if/else/elseif. Otherwise use Select.

Share this post


Link to post
Share on other sites

The basic rule would be "for a few choice" use if/else/elseif. Otherwise use Select.

and for a lot of choices use a loop.

$aX=Stringsplit("1,2,3,4,5,6,7,8,bob,fred,jill",",")
$answer="notfound"
for $i=1 to $aX[0]
if $aX[$i]="bob" then $answer="found"
Next
MsgBox(1,"",$answer)

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

and for a lot of choices use a loop.

ok, I almost get this, I want to walk through it to see if I do.

$aX=Stringsplit("1,2,3,4,5,6,7,8,bob,fred,jill",",")

that part the string and splits it based on the ","

$answer="notfound"

sets the default answer

for $i=1 to $aX[0]

$aX[0] would be the number of lines in the array, correct?

And the For makes it loop that many times, right?

if $aX[$i]="bob" then $answer="found"

checks $aX[$1] if it's "bob" then changes $answer to found...

Next

it does all of that up to the next as many times as was set at the begining...

MsgBox(1,"",$answer)

ok, cool, didn't quite get that till I walked through it...

"I'm not even supposed to be here today!" -Dante (Hicks)

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