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
2011-2-9
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 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!