How do I make a while loop that will return to a statement unless a condition is met
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Quan Seah
am 16 Apr. 2018
Kommentiert: Walter Roberson
am 16 Apr. 2018
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
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 16 Apr. 2018
If strcmp()
...
elseif strcmp()
...
else
Give message
x = ''
end
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!