How to start again from the previous step?
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to do something like:
x = input('value of x:');
y = input('value of y:');
if (x>=y)
...
else
fprintf('undesirable');
% Then I want to return to the beginning and ask for new x and y inputs. Is there a way to do this? Thank you!
댓글 수: 0
채택된 답변
Amit
2014년 1월 24일
편집: Amit
2014년 1월 24일
There are for loop and while loop, that can help you do that.
댓글 수: 4
Amit
2014년 1월 24일
편집: Amit
2014년 1월 24일
This code will work. To separate undesirable with the next one, you can use \n operator which is for new line. One problem with this code is that it will loop for only 10 times. If in 10 times, x does not become >= y, then also the code will exit. You want the loop to go on until its not undesirable. I think while loop would be better.
Try something like this:
x = 1;
y = 10;
while (x < y)
x = input('value of x:');
y = input('value of y:');
if (x < y)
fprintf('undesirable\n');
end
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!