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 ExchangeLoops 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