Is there a way to have an option in the conditional go to another part of the conditional?

I have one large for loop with nested if statements. In the first set of if statements the final result is supposed to be an fprintf statement if a value of a calculation is less than one. If it's not less than one I don't have an option because i want it to go to the elseif statement. Is there a way to do that?

Answers (2)

Look at the documentation
If the first condition is false, automatically it goes to the nes if.
If you mean a structure such as
if condition1
if condition2
fprintf(...)
else
%HERE we want to continue at THERE
end
else
%THERE
end
then NO, there is no mechanism for that.
You can use
if condition1 & condition2
fprintf(...)
else
%THERE
end
and if you need to you can use
goThere = true;
if condition1
... do a calculation here ...
if ~conditon2
goThere = false;
end
end
if ~goThere
fprintf(...)
else
%THERE
end

Categories

Find more on Document and Integrate Toolboxes in Help Center and File Exchange

Products

Asked:

on 8 Mar 2013

Community Treasure Hunt

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

Start Hunting!