可以返回多值
1
function
getGreen(ta)
2 local taKey = 1
3 local taValue = ta[taKey]
4
5 for i, val in ipairs (ta) do
6 if val == " Green " then
7 taKey = i
8 taValue = val
9
10 break
11 end
12 end
13
14 return taKey, taValue
15 end
16
17 color = { " Red " , " Green " , " Yellow " }
18 print (getGreen(color)) -- 輸出結果:2 Green
可接受可變參數
2 local taKey = 1
3 local taValue = ta[taKey]
4
5 for i, val in ipairs (ta) do
6 if val == " Green " then
7 taKey = i
8 taValue = val
9
10 break
11 end
12 end
13
14 return taKey, taValue
15 end
16
17 color = { " Red " , " Green " , " Yellow " }
18 print (getGreen(color)) -- 輸出結果:2 Green
1
function
getGreen(
)
--
"
" 表示可變參數
2

3 end


2


3 end