z = ''; while ~strcmp(z,' C to F') z = input(...) if strcmp(...) Convert... else Complain z = '' end end
How to make a repeat process for a statement in a while loop when condition is not met?
2 次查看(过去 30 天)
显示 更早的评论
Right now I am stuck as to how do I return z to asking for the conversion method if the 'C to F' is not entered correctly or nothing is entered. Help please.
clear,clc
x =[];
while isempty(x)
x = input('Make a choice(imperial or metric): ','s');
if strcmp(x,'imperial')
y = input('Please enter a value: ');
z = input('Conversion method (C to F): ','s');
if strcmp(z,'C to F')
convert(x,y,z)
end
elseif strcmp(x,'metric')
y = input('Please enter a value: ');
z = input('Conversion method (C to F): ','s');
else
x =[];
disp('Please make sure the spelling are correct!')
end
end
0 个评论
采纳的回答
Walter Roberson
2018-4-16
编辑:Walter Roberson
2018-4-17
0 个评论
更多回答(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!