IF statement restarting when condition is true

12 ビュー (過去 30 日間)
andrea vironda
andrea vironda 2016 年 3 月 12 日
編集済み: Rick Rosson 2016 年 3 月 12 日
hello i make an IF statement:
d=input('Is this spur gear mounted between two bearing? (Y/N): ','s');
if d=='N'
error('this program is not for you');
elseif d~='Y' | d~='N'
disp('you must use capital letters')
return
end
i would, if the second condition is true, to restart the code from
d=input('...
how can i do this?

採用された回答

Rick Rosson
Rick Rosson 2016 年 3 月 12 日
編集済み: Rick Rosson 2016 年 3 月 12 日
k = [];
while isempty(k)
d=input('Is this spur gear mounted between two bearing? (Y/N): ','s');
k = findstr(upper(d),'YN');
if isempty(k)
fprintf('Invalid response. Please try again.\n');
end
end

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by