|
发表于 2017-11-1 19:14:58
|
显示全部楼层
回复 creat
追问一个数组问题,现在有两个数组 a = {"north", "west", "south", "east"} 另外一 ...
hanlinjiang 发表于 2017-11-1 07:50 AM
你这个数据结构理论上需要双循环来处理- function q_2(a,b)--创建两个形参,相当于local a,b
- a = {"north", "west", "south", "east"}
- b= {"west", "east"}
- for i=1,#a--从1开始遍历表a
- do for k=1,#b--从1开始遍历表b
- do if b[k]==a[i] then return print (a[i]) end
- end
- end end
- q_2()
复制代码 对数据结构进行调整后- function q_2_b()
- local a = {"north", "west", "south", "east"}
- local b,key= {west=0, east=0}
- for i=1,#a
- do key=a[i]
- if b[key] then return print (key) end
- end end
- q_2_b()
复制代码 |
|