创建有意无限循环时python中的语法错误
我试图在python中创建一个有意的无限循环。 程序的源代码是:创建有意无限循环时python中的语法错误,python,Python,我试图在python中创建一个有意的无限循环。 程序的源代码是: count = 0 while True: count += 1 # end loop if count is greater than 10 if count > 10: break # skip 5 if count == 5: continue print count raw_input("\n\nPress the enter key to exit.") 。。。但当我试图编译它时,会出现以
count = 0
while True:
count += 1
# end loop if count is greater than 10
if count > 10:
break
# skip 5
if count == 5:
continue
print count
raw_input("\n\nPress the enter key to exit.")
。。。但当我试图编译它时,会出现以下错误消息:
there is an error in your program
SyntaxError: 'break' outside loop
代码中存在缩进错误。请尝试上面的代码
有很多可以学习的链接
Python代码的样式指南
Wiki缩进当您仍然处于while块中时,如何获得if条件?在编辑器中的缩进是否与您在本文中的缩进完全相同?您了解如何正确缩进Python代码吗?你想在
while
循环中的任何内容都需要比while
语句缩进一级。我使用的是《python for absolute初学者》一书,源代码是相同的
count=0
while True:
count += 1
# end loop if count is greater than 10
if count > 10:
break
# skip 5
if count == 5:
continue
print count
raw_input("\n\nPress the enter key to exit.")