创建有意无限循环时python中的语法错误

时间:2014-06-09 15:56:17

标签: 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.")

...但是当我尝试编译它时会出现以下错误消息:

there is an error in your program
SyntaxError: 'break' outside loop

1 个答案:

答案 0 :(得分:1)

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.")

代码上面的代码中存在缩进错误

有manylink学习缩进link1

Python代码样式指南PEP

维基缩进wiki