Jump to content
Sign in to follow this  

For something in something ?

Recommended Posts

I use for loops all the time ( For $a = 1 To $blah ) etc but I don't know what all the "For something in something" means or how it is used. I have seen examples but it makes no sense to me currently.

Could you explain the principle and offer a short and simple example?

Edited by Morthawt

Share this post

Link to post
Share on other sites

It's the same as looping through an array with for to next.

But it cannot work with multidimensional arrays, and can work with objects.

Search "For...In...Next" in help file it has examples of both arrays and objects.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post

Link to post
Share on other sites

The difference is that in a For .. To loop, you go through the index and in a For .. In loop you go through the data contained in the array. Check out this example, you will understand:

Global $aArray[5] = ["Value 1", _
    "Value 2", _
    "Another Value", _
    "And another", _
    "Last one"]

;For .. in
For $TheValue In $aArray
    ConsoleWrite($TheValue & @CRLF)

;For $i = ... to
For $i = 0 To UBound($aArray) -1
    ConsoleWrite($aArray[$i] & @CRLF)

You can see that in the For .. In loop, $TheValue is automatically assigned to the actual value of the array. It loops incrementally until the end of the array.

I hope it's clear enough.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...