vara={'1':'1','2':{'21':'21','22':'22','23':'23','24':{'241':'241','242':'242','243':'243','244':{'2441':'2441','2442':'2442','2443':'2443','2444':'2444',},},},'3':'3','4':'4','5':'5','6':'6'}///--------------------------------------------------returnfunctiontestReturn(a){for(pina){console.log(p)if(p=='2442')return;if(typeofa[p]=='object'){testReturn(a[p]);}}}functiontestReturn1(a){for(pina){varb=a[p];console.log(p)if(typeofb=='object'){for(ppinb){console.log(pp);varc=b[pp];if(typeofc=='object'){for(pppinc){console.log(ppp);vard=c[ppp];if(typeofd=='object'){for(ppppind){console.log(pppp)if(pppp=='2442')return;}}}}}}}}console.log('--return--')testReturn(a)console.log('--return1--')testReturn1(a)--return--1221222324241242243244244124423456--return1--122122232424124224324424412442return中断多层循环的时候,用递归和直接循环,结果不同。同样的条件用continue、break中断,却能得到一致的结果。也就是说只有在直接循环且return中断的条件下,是跳出所有循环的,其他情况都留有最初的一层循环,怎么解释上述情况的不同。1221222324241242243244244124423456
守着一只汪
相关分类