Borrar filtros
Borrar filtros

Changing switch statement to while loop?

2 visualizaciones (últimos 30 días)
Tyler Silva
Tyler Silva el 23 de Oct. de 2015
Editada: Thorsten el 23 de Oct. de 2015
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?

Respuesta aceptada

Thorsten
Thorsten el 23 de Oct. de 2015
Editada: Thorsten el 23 de Oct. de 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')

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by