第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

lua語言一個(gè)數(shù)組的問題。

lua語言一個(gè)數(shù)組的問題。

慕少森 2019-04-11 10:06:08
function minzhi()local days={"1","2","3","4","5","6","7","8","9","0","a","b","c","d","e","f","g","h","j","k","l","q","w","e","r","t","y","u","i","o","p","z","x","c","v","b","n","m"}endprint (minzhi())如何讓函數(shù)每次運(yùn)行,從第一個(gè)數(shù)組開起輸出,一直到最后一個(gè),又從第一個(gè)輸出,這樣循環(huán)顯示
查看完整描述

2 回答

?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊

用 closure 最簡(jiǎn)單,比如下面的代碼,每次調(diào)用 minzhi() 都會(huì)打印 days 里的元素。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

function newMinzhi()

    local days={"1","2","3","4","5","6","7","8","9","0","a","b","c","d","e","f","g","h","j","k","l","q","w",

        "e","r","t","y","u","i","o","p","z","x","c","v","b","n","m"}

    local idx = 1

    return function ()

        if idx > #days then

            idx = 1

        end

        print(days[idx])

        idx = idx + 1

    end

end

 

minzhi = newMinzhi()

minzhi()   -- 打印 1

minzhi()   -- 打印 2

minzhi()   -- 打印 3

................

 


查看完整回答
反對(duì) 回復(fù) 2019-04-12
?
九州編程

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超4個(gè)贊


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

-- 之前的版本直接把內(nèi)容打印出來了,現(xiàn)在的版本改成返回 days 中的值。

 

function newMinzhi()

    local days= {"中", "國"}

    local idx = 1

    return function ()

        if idx > #days then

            idx = 1

        end

        local ret = days[idx]

        idx = idx + 1

        return ret

    end

end

minzhi = newMinzhi()

print(minzhi())

print(minzhi())


 


查看完整回答
反對(duì) 回復(fù) 2019-04-12
  • 2 回答
  • 0 關(guān)注
  • 887 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)