3

I have created an array as xArray:=[2, 3, 4]

I need to use these values one by one in a loop.

I have tried using a counter variable, but it didn't work.

There's even a predefined "A_Index" variable in ahk scripts. Can someone elaborate on that? It might be the solution.

4
  • I don't know AHK, but searching in the docs I found the snippet Loop %ArrayCount% { element := Array%A_Index% }, (where ArrayCount is the size of the array) which seems to do an array traversal. Source: autohotkey.com/docs/misc/Arrays.htm Commented Jun 13, 2014 at 0:41
  • but then i want to access the value of each element.. this would just help me to get the Count.. Commented Jun 13, 2014 at 0:44
  • The variable element seems to receive the value in the given position, similar to element = Array[i]; in C. Commented Jun 13, 2014 at 0:45
  • @Mephy They way you've described is the "old" array notation using sequentially numbered variables as pseudo arrays. AHK_L on the other hand provides support for actual arrays, similar to JavaScript's syntax and usage. For direct comparison, please read AHK_L arrays. Commented Jun 13, 2014 at 10:05

1 Answer 1

4
xArray:=[2, 3, 4] 
for key, val in xArray
    MsgBox % val
Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to use array values and regular text in a single MsgBox?
@StevenVascellaro MsgBox % "this is a regular text " val " some more text"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.