i want to get an error if the user enters an input other than 1 to 16. even negative and zero should give error
1 回表示 (過去 30 日間)
古いコメントを表示
while element > 16
disp 'Error you entered a a number greater than 16. Please enter again!'
element =input(prompt);
end
0 件のコメント
採用された回答
Walter Roberson
2018 年 1 月 2 日
while true
element = input(prompt);
if ismember(element, 1:16); break; end
end
5 件のコメント
Walter Roberson
2018 年 1 月 3 日
"Why ugly while loop in this case?"
Situations like this almost always want to keep prompting until valid input is entered.
その他の回答 (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!