MATLAB Answers

How to write repeating questions

1 view (last 30 days)
William Ward
William Ward on 8 Apr 2021
Commented: Adam Danz on 13 Apr 2021
I'm looking to loop questions continuously until I get a 'no' answer.
For example when the program asks if there are any more rooms and I answer yes then it should ask the dimensions. And once I have inputted that then it should ask if there are anymore rooms, and so on until I say there aren't anymore rooms.
  1 Comment
Adam Danz
Adam Danz on 13 Apr 2021
> [flag] This is no longer appropriate and I would like it deleted so I no longer receive notifications/help.
In the upper left corner, click "unfollow" to stop receiving notifications on this thread.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 8 Apr 2021
I assume you're using input to prompt users to respond. This is the least robust, most error-prone method of getting information from users.
I suggest using a question dialog box. For example: [see this answer].
To address your question, you can wrap the input command in a while-loop that continually saves the user's response and exits when the user enters 'no'.
Adam Danz
Adam Danz on 12 Apr 2021
I would create a simple, short while-loop that merely asks "are there any more floors" followed by a conditional statement that calls a "YES" routine and a "NO" routine.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!