查看单个帖子
旧 2008-04-23, 17:54   #1
tguranus
初级会员
 
注册日期: 2008-04-21
年龄: 38
帖子: 1
声望力: 0
tguranus 正向着好的方向发展
问题 [求助]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
break;
end
这是一个子程序,为了确保正确的返回量在switch语句的最后使用了otherwise break语句,但是程序执行时总是提醒我break出现在循环外,让我用return代替(A BREAK statement appeared outside of a loop. Use RETURN instead),可是我用return之后程序又陷入无限循环中,无法得到正确结果,请问这是什么原因造成的啊?
tguranus 当前离线   回复时引用此帖