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!