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?

답변 (1개)

Walter Roberson
Walter Roberson 2011년 2월 9일

2 개 추천

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

태그

질문:

2011년 2월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by