MATLAB Answers

Tonu
0

How to exit a program or rather not process further code if a condition is not met ?

Asked by Tonu
on 21 Nov 2012
Latest activity Answered by Anmar Mohammed on 11 Jul 2018
Say for example a check for a variable 'a' ?
If a is not equal to (a~= 1) abort the program and do not execute further codes , else continue ?
Thanks,
Tonu

  0 Comments

Sign in to comment.

3 Answers

Answer by Arthur
on 21 Nov 2012
 Accepted Answer

Error should only be used when there is, ehm, an error. To stop the execution otherwise, use return.

  2 Comments

I prefer this. Example:
if a ~= 1
return;
end
The return statement returns control to the program that called the function, it doesn't terminate execution unless called from the top level.
Is there a way to gracefully stop execution within a called function?

Sign in to comment.


Answer by Tonu
on 21 Nov 2012

Hey I just used the 'error' function , and it is working fine. If any other option , please suggest, Thanks,Tonu

  0 Comments

Sign in to comment.


Answer by Anmar Mohammed on 11 Jul 2018

Thank you very much, greetings.

  0 Comments

Sign in to comment.