如何在python的while循环中停止函数 [英] How to stop a function in a while loop in python

查看:1458
本文介绍了如何在python的while循环中停止函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想停止功能,但不希望终止脚本.

Basically I want to stop a function but not by terminating the script.

While True:
  do function A()
  do function B()
  if ( condition ):
    function B.stop()

我的意思是,当条件满足时,while循环仍会运行,但是在while循环的下一次迭代中,它仅执行A功能,而不再执行B功能.我想知道是否可以将其归档在Python? 谢谢

What I mean is when the condition is met, the while loop still runs but in the next iteration of the while loop, it only does function A, no longer does it do function B. I wonder if we can archive this in python? Thanks

推荐答案

如何在循环中使用标记

flag = True

while True:
  if flag:
    do function B()

  if condition:
    flag = false

这篇关于如何在python的while循环中停止函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆