MATLAB Answers

How can I skip right to the end of a script?

67 views (last 30 days)
Bogdan on 13 Apr 2016
Commented: Bogdan on 14 Apr 2016
I have a problem with a MATLAB script which I don't know how to fix it.
I am in the middle of the script and I need for it to jump straight to the end of it. There is no equivalent for goto in MATLAB so this is out of the question and, right now, rewriting the code is not an option.
A piece of the source is this:
if (i==m_sonde-1)
% *Here* I need to exit the program
How do I do it?

Accepted Answer

Kuifeng on 13 Apr 2016
help break %does this help?


J. Webster
J. Webster on 13 Apr 2016
Note that "break" will pop you out of the current loop.
To leave the current function, you should use "return".
Bogdan on 14 Apr 2016
Yes, "return" was the correct answer.
Thank you very much!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!