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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
while element > 16
disp 'Error you entered a a number greater than 16. Please enter again!'
element =input(prompt);
end
0 commentaires
Réponse acceptée
Walter Roberson
le 2 Jan 2018
while true
element = input(prompt);
if ismember(element, 1:16); break; end
end
5 commentaires
Walter Roberson
le 3 Jan 2018
"Why ugly while loop in this case?"
Situations like this almost always want to keep prompting until valid input is entered.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!