Returning Back to some Previous Loop if a separate condition is met

15 views (last 30 days)
What is the most efficient way for me to accomplish the following:
I want to loop some function while a condition is true.
while (something is true)
do this
end
Once that something is no longer true, essentially what I want to do is find a way to go back to that "while loop" if a separate condition is met. For instance:
while (something is true)
do this
end
input()
if (if that input is a certain value)
GO BACK to the previous loop
end
Is there any way to get 'back' to the other loop? Essentially I wan't to ask "are you sure you want to stop doing that while loop?" and if not, go back to the while loop again.
Thanks

Answers (1)

Walter Roberson
Walter Roberson on 26 Sep 2011
Nope, no way of doing that. So don't. Instead,
while true
while (something is true)
do this
end
yesno = input()
if yesno ~= the certain value
break;
end
end

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!