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

137 次查看(过去 30 天)
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

采纳的回答

Arthur
Arthur 2012-11-21
Error should only be used when there is, ehm, an error. To stop the execution otherwise, use return.
  2 个评论
Glenn
Glenn 2018-4-17
编辑:Glenn 2018-4-17
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?

请先登录,再进行评论。

更多回答(2 个)

Tonu
Tonu 2012-11-21
Hey I just used the 'error' function , and it is working fine. If any other option , please suggest, Thanks,Tonu
  1 个评论
Aishwarya Lakshmi Srinivasan
Hi, can you please elaborate this ? In my case I am trying to abort a function that is currently running by setting the flag to false when abort button is pressed in an app designer.

请先登录,再进行评论。


Anmar Mohammed
Anmar Mohammed 2018-7-11
Thank you very much, greetings.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by