Break在循环python之外

Edw*_*ere -1 python loops if-statement break

while True:
    x = raw_input()
    if x =="personal information": 
         print' Edward , Height: 5,10 , EYES: brown , STATE: IL TOWN:  , SS:'
    elif x =="journal":
         name_of_file = raw_input("What is the name of the file: ")
         completeName = "C:\\python\\" + name_of_file + ".txt"
         file1 = open(completeName , "w")
         toFile = raw_input("Write what you want into the field")
         file1.write(toFile)
         file1.close()
else:
 break 
Run Code Online (Sandbox Code Playgroud)

脚本继续给我一个错误,说break是在循环之外是缩进错了吗?

Jul*_*ian 5

是的,看看你的帖子.你else可能意味着要使用if语句的缩进级别.

else语句的while陈述完全不同.