本文介绍了Python:'break' 外循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在以下python代码中:
in the following python code:
narg=len(sys.argv)
print "@length arg= ", narg
if narg == 1:
print "@Usage: input_filename nelements nintervals"
break
我明白了:
SyntaxError: 'break' outside loop
为什么?
推荐答案
因为 break 不能用于跳出 if - 它只能跳出循环.这就是 Python(和大多数其他语言)被指定的行为方式.
Because break cannot be used to break out of an if - it can only break out of loops. That's the way Python (and most other languages) are specified to behave.
你想做什么?也许你应该使用 sys.exit()
或 return
代替?
What are you trying to do? Perhaps you should use sys.exit()
or return
instead?
这篇关于Python:'break' 外循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!