Changing switch statement to while loop?

2 views (last 30 days)
I'll paste my script, but I was wondering how to change my switch statement to a while loop. With the switch if the user enters incorrect info, they can only correct one piece of it. If i make a while loop then I want the user to be able to correct as much as they want. Do i need a while loop for each piece of info?

Accepted Answer

Thorsten
Thorsten on 23 Oct 2015
Edited: Thorsten on 23 Oct 2015
You can use the menu in the while loop as follows:
while menu('Information Correct?','Yes','No') == 2
wrong = menu('What is Wrong?','Name','Age','City','State','Zip');
switch wrong
case 1 % Name is Wrong
Name = input('Enter your name: ','s');
case 2 % Age is Wrong
Age = input('Enter your age: ');
case 3 % City is Wrong
City = input('Enter your City: ','s');
case 4 % State is Wrong
State = input('Enter your State: ','s');
case 5 % Zip Wrong
Zip = input('Enter you Zip code: ');
end
end
% while loop left, everything is correct
fprintf('Nice Work! \n')

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!