Tables as Arrays in Lua

 Tables as Arrays in Lua


Lua's tables can be used to represent arrays, with integer keys and consecutive indices starting at 1. Here's an example:



local my_array = {"apple", "banana", "cherry", "durian"}

for i = 1, #my_array do

  print(my_array[i])

end

In this example, my_array is an array of strings. The for i = 1, #my_array do line loops over each element of the array using its index.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...