Problem understanding for-loop

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ed1chandler
Posts: 15
Joined: 15 May 2015, 11:18

Problem understanding for-loop

17 Mar 2016, 10:47

From the help:

Code: Select all

; List the key-value pairs of an object:
colours := Object("red", 0xFF0000, "blue", 0x0000FF, "green", 0x00FF00)
; The above expression could be used directly in place of "colours" below:
for k, v in colours
    s .= k "=" v "`n"
MsgBox % s
This returns a populated MsgBox, as expected.

However, this ...

Code: Select all

Things := Object()
Loop 5
{
	Thing := Object()
	Thing.Name := "Name" . A_Index
	Things.Push(Thing)
}
for Thing in Things
	p .= Thing.Name
MsgBox % p
Returns an empty MsgBox. What nuance is escaping me?
thingy

Re: Problem understanding for-loop

17 Mar 2016, 10:51

its "for k, v" so "for thing, thingy" should do it.

Code: Select all

for Thing,Thingy in Things
	p .= Thingy.Name
ed1chandler
Posts: 15
Joined: 15 May 2015, 11:18

Re: Problem understanding for-loop

17 Mar 2016, 13:20

Yep, that was it. I neglected to realize I was dealing with an array of arrays.

Thanks for helping me find my thingy. ;)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: macromint, peter_ahk, Rauvagol and 307 guests