MATLAB Answers

IF statement restarting when condition is true

27 views (last 30 days)
andrea vironda
andrea vironda on 12 Mar 2016
Edited: Rick Rosson on 12 Mar 2016
hello i make an IF statement:
d=input('Is this spur gear mounted between two bearing? (Y/N): ','s');
if d=='N'
error('this program is not for you');
elseif d~='Y' | d~='N'
disp('you must use capital letters')
return
end
i would, if the second condition is true, to restart the code from
d=input('...
how can i do this?

  0 Comments

Sign in to comment.

Accepted Answer

Rick Rosson
Rick Rosson on 12 Mar 2016
Edited: Rick Rosson on 12 Mar 2016
k = [];
while isempty(k)
d=input('Is this spur gear mounted between two bearing? (Y/N): ','s');
k = findstr(upper(d),'YN');
if isempty(k)
fprintf('Invalid response. Please try again.\n');
end
end

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.