How to insert a loop into a program?

My engineering class is learning how to write programs in matlab, and so I got bored during one of my classes and started reading ahead and begin writing a program to determine someone's age and how many days until their next birthday. Given my inexperience with writing code, the program is super long, but it works flawlessly. I'm only having one problem...
After the user inputs their year, day, and month of birth, and also the current year, day, and month, the program asks if the information they have put in is correct in a menu and their options are "yes" or "no". Write now no matter what they select nothing happens because I don't know how to set up the loop. If they answer yes i want the program to just keep going, and if they answer know, i want the program to loop back to that set of questions again until they answer yes. How do I do this?

Réponses (1)

Walter Roberson
Walter Roberson le 9 Fév 2011

2 votes

need_the_info = true;
while need_the_info
....
if strcmpi(user_reply,'Yes')
need_the_info = false;
break;
end
end

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by