我可以为python while循环指定一个默认值吗



我有一个while循环的形式:

while temp is True:
do stuff
if the outcome is what I want:
temp = False

我似乎经常使用这种结构。所以我的问题是,是否有一种方法可以在while语句本身初始化temp,而不必在其前面加temp = True

您可以使用:

while True:
do stuff
if the outcome is what I want:
break

最新更新