【发布时间】:2017-04-23 03:45:52
【问题描述】:
当我激活案例“6”时,如何退出案例“5”?我似乎无法退出循环。我试过休息一下;在案例“6”中,但这似乎不起作用。
case '5': //receive a '5' from serial com port and execute auto docking
while(1)
{
north =0;
south=0;
east=0;
west=0;
scanmovement();
for(index=0;index<7;index++)
{
getdirection(index);
}
arlomove();
obstacleavoidance();
}
break;
case '6': //receive '6' from serial com port and stop auto docking
//somethingsomething
//break out of while loop in case '5' when this is activated
break;
【问题讨论】:
-
请编辑您的代码以显示退出 while 循环的某些原因,最好是
if语句。 -
所以要明确一点,这是多线程的还是以其他方式可重入的(例如,通过信号处理程序,或
case '5':循环中调用的方法之一)?因为否则,您将永远无法到达case '6':来终止循环。 -
我已经编辑了代码
-
这是在函数内部吗?
-
是的,它在主函数的while循环中运行
标签: c++11