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

采纳的回答

Walter Roberson
Walter Roberson 2018-1-2
while true
element = input(prompt);
if ismember(element, 1:16); break; end
end
  5 个评论
Walter Roberson
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by