Return to input, how?
6 views (last 30 days)
Show older comments
I'm trying to create an input form that takes two different answers. And when you type a wrong answer, I want it to go back to the input and start over.
My code is (the original text was in danish, so i put a bad english example in the forms):
value = input('Write hi or goodbye','s');
if isequal(value, 'hi')
fprintf('Hello\n');
elseif isequal(value, 'goodbye')
fprintf('see you\n');
else
fprintf('wrong answer try again!\n');
end
So what can i do about the else statement? I was thinking about some message saying: The answer is incorrect, will you try again? (y/n)
Thanks in advance!
0 Comments
Answers (1)
Walter Roberson
on 15 May 2013
while true
value = ...
if ....
break;
else
wrong answer
end
end
Notice that there is no "break" for the case where you want it to loop back.
See Also
Categories
Find more on Two y-axis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!