溫馨提示×

python怎么強制結束遞歸函數

九三
1604
2021-02-18 19:58:06
欄目: 編程語言

python怎么強制結束遞歸函數

在python中強制結束遞歸函數的方法以下兩種

1.使用return語句結束

def count(dict, key, depth):

if key is not None:

if key == 42:

return depth

return count(map, map[key][0], depth+1)

return count(map, map[key][1], depth+1)

2.通過在遞歸函數外定義一個isGo全局變量結束

var isGo:Boolean=true

functionarr_all(pre:Array,nex:Array) {

if(isGo==false){return}

var j:uint=nex.length;

if (j==1) {

var t=[];

for (var i:uint=0;it.push(pre[i]);

}

t.push(nex[0]);

isGo =false;

returninfo.appendText("\n"+pc(t));

}

for (var k:uint=0; kvar p:Array=pre.slice();

var s:Array=nex.slice();

p.push(s.splice(k,1));

arr_all(p,s);

}

}

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女