[英]Break is outside the loop python
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
脚本不断给我一个错误,说中断不在循环内缩进是否错误?
是的,请查看您的帖子。 您的else
可能意味着使用if
语句的缩进级别。
else
语句的while
语句做的事情完全不同。
不,这不是识别错误。 您通常会“跳出”循环。 while语句中的else部分不是循环构造。 如果执行此操作,则会发现相同的错误
In [12]: if True:
....: break
SyntaxError: 'break' outside loop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.