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!