What is the command to repeat the program?

14 ビュー (過去 30 日間)
Marwan Khalil
Marwan Khalil 2016 年 10 月 5 日
回答済み: Massimo Zanetti 2016 年 10 月 5 日
So I am making an if statement, I wanted to know if there is a command that restarts the program for the user. So the program starts by asking the user for some input, if the input is invalid then it outputs that it is invalid, I want it to be that the program then restarts and asks the user again for input, so if it is valid, the user can keep going with the program.

回答 (1 件)

Massimo Zanetti
Massimo Zanetti 2016 年 10 月 5 日
Here it is:
while 1
x = input('Enter your input: ');
%check the input according to your needs
%for example here I check the input is even number
if rem(x,2)==0
break;
end
end
%do whatever you want with your right input
disp('done');

カテゴリ

Help Center および File ExchangeFunctions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by