栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何停止While循环?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何停止While循环?

只需正确缩进代码即可:

def determine_period(universe_array):    period=0    tmp=universe_array    while True:        tmp=apply_rules(tmp)#aplly_rules is a another function        period+=1        if numpy.array_equal(tmp,universe_array) is True: return period        if period>12:  #i wrote this line to stop it..but seems its doesnt work....help.. return 0        else:    return period

您需要了解,

break
示例中的语句将退出您使用创建的无限循环
whileTrue
。因此,当中断条件为True时,程序将退出无限循环并继续执行下一个缩进块。由于代码中没有以下代码块,因此该函数结束并且不返回任何内容。因此,我通过将
break
语句替换为语句来修复了您的代码
return

按照您的想法使用无限循环,这是编写它的最佳方法:

def determine_period(universe_array):    period=0    tmp=universe_array    while True:        tmp=apply_rules(tmp)#aplly_rules is a another function        period+=1        if numpy.array_equal(tmp,universe_array) is True: break        if period>12:  #i wrote this line to stop it..but seems its doesnt work....help.. period = 0 break    return period


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/662698.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号