Jump to content

Recommended Posts

Posted (edited)

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
Posted

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)
Next

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

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.

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
×
×
  • Create New...