A way to exit out of a function in the code while it is running?

조회 수: 168 (최근 30일)
Luke
Luke 2014년 9월 18일
댓글: Michael Haderlein 2014년 9월 18일
I have a function that runs and resets a variable with respect to a few different things, once this variable is set as a string and not a number which it originally is, i wish to exit the function and not carry on to reset the variable further on, is there a way to do this?
Either a condition to end once that variable is set as a string or a break within the code? Or maybe another command that would stop the function and output the variable there.
Cheers for the help!

답변 (1개)

Adam
Adam 2014년 9월 18일
if ischar( varname )
return;
end
  댓글 수: 2
Luke
Luke 2014년 9월 18일
Will 'return;' end the function at a specific step if i enter it in there?
Michael Haderlein
Michael Haderlein 2014년 9월 18일
return will stop the function and immediately go back to the invoking function, i.e. the function which called the one which is stopped.
break will jump to the end of the loop and proceed with the current function.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by