MATLAB Answers

Can sections be skipped with something similar to "return" or "continue"?

46 views (last 30 days)
Steeven on 13 Apr 2018
Commented: Sean de Wolski on 4 May 2020
In MatLab live scripts one can split the code into sections. This may be for a visual overview and also allows for running just a specific section at a time instead of the entire code.
I would like to ask if this sectioning is more than visual and practical but also recognizable by the code itself - can the code e.g. treat a section in the same manner as, say, a loop or a function? If so, can a section be skipped by a command similar to what commands such as return or continue do?
So, the question in short is: Is there a way to skip an entire section if a condition is met? Something like:
if ~toggle; _skip this section_; end
Skipping the rest of a function or loop is easy with e.g.:
if ~toggle; return; end
and I am looking for this similar feature for skipping a section. I am asking if this is possible before wrapping an entire section in an if-statement.

Answers (1)

Jared MacDonald
Jared MacDonald on 4 May 2020
Hi Steeven,
There is currently no way to skip a section other than writing a conditional. This is an intriguing suggestion, though, and we've made a note of it.
Sean de Wolski
Sean de Wolski on 4 May 2020
I agree John. And the refactor capability added a few releases ago to the live editor makes it even easier to convert something to a local or separate file function!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by