An "if" statement is within another "if" statement which inside a "while" loop. How to end the second "if" statement when a condition is met in the first "if" without breaking the while loop? "return" in the first "if" just ends first "if"

Answers (1)

I would use break (link). It should only terminate execution of the innermost loop it appears in.
Consider the continue statement as well, depending on what you want to do.
Experiment to get the result you want.

Categories

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

Asked:

on 14 Apr 2018

Answered:

on 14 Apr 2018

Community Treasure Hunt

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

Start Hunting!