필터 지우기
필터 지우기

How to exit an if else loop without continuing with the other lines of code?

조회 수: 1 (최근 30일)
Manuel S Mathew
Manuel S Mathew 2020년 5월 27일
댓글: Stephen23 2020년 5월 27일
This is my code
prompt = 'Which Schedule Should Be Used? (1/2) \n';
x = input(prompt);
if x == 1
connection = connection_schedule1();
elseif x == 2
connection = connection_schedule2();
else
fprintf('Unrecognized Input \n')
end
connection_schedule1 and connection_schedule2 are two functions that make a schedule for my code. If someone enters any other term than 1 or 2, I would like to display the message 'Unrecognized Input' and exit without proceeding through the next lines of code. Is this possible? Currently, my error message is displayed but it shows also other error in the succeeding lines of code that requires the schedules that I input. It would also be helpful if I can bring back the execution to the first line shown here if an invalid input is provided. Many thanks in advance.
  댓글 수: 1
Stephen23
Stephen23 2020년 5월 27일
"It would also be helpful if I can bring back the execution to the first line shown here if an invalid input is provided"
Use a while or a for loop.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by