Borrar filtros
Borrar filtros

How do I make a while loop that will return to a statement unless a condition is met

1 visualización (últimos 30 días)
I am trying to make a while loop that will goes on forever unless a condition is met, in this case I want the loop to keep repeating unless I enter the word imperial or metric. And when I enter other words it will continue ask the question "Please make a choice", the code i have here just opts out whenever i enter other words
clear,clc
x = [];
while isempty(x)
x = input('Please make a choice (imperial or metric) - ','s');
if strcmp(x,'imperial')
disp('yes')
if strcmp(x,'metric')
disp('no')
end
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Abr. de 2018
If strcmp()
...
elseif strcmp()
...
else
Give message
x = ''
end
  2 comentarios
Quan Seah
Quan Seah el 16 de Abr. de 2018
I tried your answer it seems like i still get the same problem when i enter words other than imperial and metric, it just opts out of the loop

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.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by