Renderer Posted February 28, 2017 Share Posted February 28, 2017 Hi guys ! How can i iterate a 2d array in AutoIt? Thanks in advance! Link to comment Share on other sites More sharing options...
czardas Posted February 28, 2017 Share Posted February 28, 2017 ??? Do you mean? $aInterate = $aArray operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Jfish Posted February 28, 2017 Share Posted February 28, 2017 (edited) When you say "iterate" you mean refer to the elements in a loop? If so, its just rows and columns. Use _arrayDisplay to visualize the data before you loop. Here is an example: #include <Array.au3> global $reproArray[5][2]=[["Bob",34],["James",22],["Sally",18],["David",43],["Cindy",28]] ;visualize data _ArrayDisplay($reproArray) ; walk 2d array for $a=0 to ubound($reproArray)-1 ConsoleWrite("Name: " & $reproArray[$a][0]&" age: "&$reproArray[$a][1] & @crlf) Next Edited February 28, 2017 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
RTFC Posted February 28, 2017 Share Posted February 28, 2017 @Jfish: I don't think that example is very helpful; not only is the column dimension wrong, the script is still treating the array as if it were 1D, because it does not loop through the columns. Instead, I would suggest using nested for-next loops (one per dimension), like so: Global $reproArray[6][2]=[["NAME","AGE"],["Bob",34],["James",22],["Sally",18],["David",43],["Cindy",28]] ; walk 2d array For $rowindex=0 to Ubound($reproArray,1)-1 For $colindex=0 to Ubound($reproArray,2)-1 ConsoleWrite($reproArray[$rowindex][$colindex] & @TAB) Next ConsoleWrite(@CRLF) Next This can easily be scaled up to handle any number of array dimensions. My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
Jfish Posted February 28, 2017 Share Posted February 28, 2017 Oops on the dimensions. Posted that a bit too quick. Also agree nested example is better Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
RTFC Posted February 28, 2017 Share Posted February 28, 2017 No worries, JFish. Just a harmless typo... Jfish 1 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now