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

조회 수: 105 (최근 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
Aishwarya Lakshmi Srinivasan 2021년 3월 8일
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에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by