For Loop on Lua

前端 未结 3 1224
有刺的猬
有刺的猬 2021-01-31 13:12

My assignment is how to do a for loop. I have figured it out in terms of numbers but cannot figure it out in terms of names. I would like to create a for loop that runs down a l

3条回答
  •  情书的邮戳
    2021-01-31 13:39

    names = {'John', 'Joe', 'Steve'}
    for names = 1, 3 do
      print (names)
    end
    
    1. You're deleting your table and replacing it with an int
    2. You aren't pulling a value from the table

    Try:

    names = {'John','Joe','Steve'}
    for i = 1,3 do
        print(names[i])
    end
    

提交回复
热议问题