Use of "return" in simple if statement
85 次查看(过去 30 天)
显示 更早的评论
Hi
I have of course read the explanations regarding the return statement. Still in the following case:
if (parameter < 1)
disp('Wrong parameters...');
return
end
I don't see what difference it makes if we use "return" here or we dispense with it..
Thanks
1 个评论
Image Analyst
2013-1-25
Just a suggestion - instead of disp() you might use
uiwait(warnglg('Wrong parameters...'));
I think it's a little nicer to have a popup message box. Better yet, use sprintf() to create your string and tell your users what they entered and what the valid range is.
采纳的回答
Walter Roberson
2013-1-25
If you do not "return" then the rest of the function would be executed.
3 个评论
Walter Roberson
2017-3-7
return(g)
This tells me that R has return() and that typically you would need to tell it what to return.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!