![]() |
[求助]switch语句中的otherwise
程序段如下:
function distance=metric(x,y) if x==y distance=0; else distance=1; end switch(y) case 0 if x==0 distance=0.0458; end if x==1 distance=2; end if x==2; distance=1.0458; end case 1 if x==0 distance=2; end if x==1 distance=0.0458; end if x==2 distance=1.0458; end otherwise [COLOR="Red"]break[/COLOR]; end 这是一个子程序,为了确保正确的返回量在switch语句的最后使用了[COLOR="Red"]otherwise break[/COLOR]语句,但是程序执行时总是提醒我break出现在循环外,让我用return代替(A BREAK statement appeared outside of a loop. Use RETURN instead),可是我用return之后程序又陷入无限循环中,无法得到正确结果,请问这是什么原因造成的啊? |
从这个程序看,return和无限循环没有关系,导致死循环的应该是调用metric的程序
|
所有时间均为北京时间。现在的时间是 11:04。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.