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 visualización (últimos 30 días)
while element > 16
disp 'Error you entered a a number greater than 16. Please enter again!'
element =input(prompt);
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 2 de En. de 2018
while true
element = input(prompt);
if ismember(element, 1:16); break; end
end
  5 comentarios
Walter Roberson
Walter Roberson el 3 de En. de 2018
"Why ugly while loop in this case?"
Situations like this almost always want to keep prompting until valid input is entered.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by