An array of Lua

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.