Effacer les filtres
Effacer les filtres

IF statement restarting when condition is true

3 vues (au cours des 30 derniers jours)
andrea vironda
andrea vironda le 12 Mar 2016
Modifié(e) : Rick Rosson le 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?

Réponse acceptée

Rick Rosson
Rick Rosson le 12 Mar 2016
Modifié(e) : Rick Rosson le 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

Plus de réponses (0)

Catégories

En savoir plus sur Gears dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by