欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Lua中的遞歸函數(shù)寫法實(shí)例

 更新時(shí)間:2015年04月22日 09:56:21   投稿:junjie  
這篇文章主要介紹了Lua中的遞歸函數(shù)寫法實(shí)例,本文直接給出代碼實(shí)例,并作了簡(jiǎn)潔注釋,需要的朋友可以參考下

先看例子吧:

復(fù)制代碼 代碼如下:

function foo(i) --1 
    print("i: ", i) 
    return i 
end 
 
do 
 
--local foo; --2 
 local foo = function (i) --3 
    if i < 1 then 
        return 1 
    else 
        return i * foo(i - 1) --4 
    end 
 end 
 
 local a = foo(4) 
 print("a: ", a) 
 
end 

上面的例子,到if里面調(diào)用了foo(..),它會(huì)調(diào)用到do..end塊里面的foo也就實(shí)現(xiàn)了局部函數(shù)的遞歸。

相關(guān)文章

最新評(píng)論