Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 在另一个循环中打断一个循环_Loops_Break_Python 3.5 - Fatal编程技术网

Loops 在另一个循环中打断一个循环

Loops 在另一个循环中打断一个循环,loops,break,python-3.5,Loops,Break,Python 3.5,我试图在Python中打破两个循环,一个循环在另一个循环中。当然,当在循环中使用break函数时,它只会中断它所在的循环。代码如下: while True: #Want to break this x, y, z = sense.get_accelerometer_raw().values() x = abs(x) y = abs(y) z = abs(z) sense.show_message(strftime('%H:%M', gmtime()),

我试图在Python中打破两个循环,一个循环在另一个循环中。当然,当在循环中使用break函数时,它只会中断它所在的循环。代码如下:

while True:   #Want to break this
    x, y, z = sense.get_accelerometer_raw().values()
    x = abs(x)
    y = abs(y)
    z = abs(z)
    sense.show_message(strftime('%H:%M', gmtime()), scroll_speed= 0.05, text_colour=[0, 255, 0], back_colour=[255, 0, 0])
    if x > 2 or y > 2 or z > 2 :   #Want to break this as well
        break #Break goes here??

我想打破从顶行开始的循环和从第7行开始的循环。如何?

如果
不是一个循环
If
是一条接受布尔值(true或false)并根据结果执行代码的语句

也就是说,你写的东西会有用的

if x > 2 or y > 2 or z > 2 :   #Want to break this as well
    break #Break goes here??

如果
x>2或y>2或z>2
,此代码将中断
while True
循环。如果
不是循环,则新闻快讯:
。并删除不相关的rasppi&3.5标记。@Chris_Rands:甚至不是这样:这是“如何在Python中从if中突破”的重复,但问题并不存在!我是个白痴——我刚刚意识到我做了什么。很抱歉