Jump to content

for every [a,b,c,d]


Recommended Posts

this is a useful and somewhat popular method for iterations:

FOR $a IN [a,b,c,d] (similar to DOS batch command), or..

FOREACH $a [a,b,c,d] (similar to tcl)

they both do the same thing. changing variable $a for every element of the set.

i'm trying to do something similar and can't find the v3 equivalant.

is this available in v3 or do i have to hack my own function?

:ph34r:

Link to comment
Share on other sites

  • Developers

You probably want to StringSplit the string into an array and then do a for.. next loop.

$Arr = StringSplit("a,b,c,d",",")
For $x = 1 to $arr[0]
     msgbox(0,'test',$arr[$x])
next

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

That's a little different from his intention though.

He's looking for something that would do this.

$Arr = StringSplit("Silly Rabbit", " ");
Foreach $Val in $Arr
    MsgBox(0, 'Array Value', $Val);
EndForeach

Which would return:

2

Silly

Rabbit

At least, that's how I see it. I use Foreach a lot in PHP, it's really handy.

But JdeB is right, it's easier to just go with a regular for loop. It would be different if AutoIt supported Associative arrays, then the For...In construct would be very handy. But otherwise your best bet is something like what JdeB posted.

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...