Jump to content

Select Or If?


Recommended Posts

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)

Link to comment
Share on other sites

  • Administrators

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.

Link to comment
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.

Link to comment
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)

Link to comment
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
 Share

  • Recently Browsing   0 members

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