Lua arrays
arrays, which are collections of elements of the same data type arranged in a certain order, can be one-dimensional and multidimensional arrays.
The index key value of the Lua array can be represented by an integer, and the size of the array is not fixed.
Array = {"Lua", "Tutorial"}for i= 0, 2 do print (Array[i]) end
The For loop pattern starts with the subscript starting at 1, so the initial value of I is set to 0 by default
Operation Result:
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/A4/55/wKioL1mozhfBLqxuAAAyKcTAhOc548.jpg-wh_500x0-wm_ 3-wmp_4-s_2213758223.jpg "title=" arr. JPG "alt=" Wkiol1mozhfblqxuaaaykctahoc548.jpg-wh_50 "/>
===============================================================
Multidimensional arrays
--Initialize array = {}for i = 1, 3 doarray[i] = {}for J = 1,3 Doarray[i][j] = i*jendend--Access array for i = 1, 3 dofor j = 1, 3 dopr Int (array[i][j]) endend
Operation Result:
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/A4/55/wKioL1mo0bfCR5sdAAA8Ectknrk270.jpg-wh_500x0-wm_ 3-wmp_4-s_546448150.jpg "title=" Duoa. JPG "alt=" Wkiol1mo0bfcr5sdaaa8ectknrk270.jpg-wh_50 "/>
====================================================================
Three-row, three-column array of different index keys in a multidimensional array:
--Initialize array = {}maxrows = 3maxColumns = 3for row = 1, maxRows dofor col = 1, maxcolumns doarray[row * maxcolumns + col] = row * colendend--Access array for row = 1, maxRows dofor col = 1, maxcolumns doprint (array[row * maxcolumns + col]) endend
Operation Result:
650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/05/A4/wKiom1mo02HxqNjTAAA-EWIAMF0774.jpg-wh_500x0-wm_ 3-wmp_4-s_981656810.jpg "title=" Arrindex. JPG "alt=" Wkiom1mo02hxqnjtaaa-ewiamf0774.jpg-wh_50 "/>
This article is from the "enjoy the Joy of Technology" blog, please be sure to keep this source http://liam2199.blog.51cto.com/2879872/1961872
An array of Lua