我对编程和 Python 都很陌生。现在有几次,我创建了一个感觉很尴尬的程序流程,我想知道我是否遵循了最佳实践。这在概念上是我想做的:
def pseudocode():
while some condition is true:
do some stuff
if a condition is met:
break out of the while loop
now do a thing once, but only if you never broke out of the loop above
我最终所做的工作,但不知何故感觉不对:
def pseudocode():
while some condition is true:
do some stuff
if some condition is met:
some_condition_met = True
break out of the while loop
if some_condition_met is False:
do a thing
有没有更好的办法?