Jump to next loop (alternative goto)

6 views (last 30 days)
BdS
BdS on 27 Mar 2019
Commented: BdS on 27 Mar 2019
Hi,
my code is mentioned below. The question is green after % if statement. May you help me?
function NewRanks=createRebRankings(f_Ranks,RebRanks,RebIndi)
nDates=size(f_Ranks,1);
nRebDates=size(RebRanks,1);
nRebIndi=length(RebIndi);
nFactors=size(f_Ranks(1,1,:),3);
nInstr=size(f_Ranks(1,:,1),2);
NewRanks=NaN(nDates,nInstr,nFactors);
for f=1:nFactors
NewRanks(1,:,f)=f_Ranks(1,:,f);
for d=2:nDates
for i=2:nRebIndi
if RebIndi(i)==0
NewRanks(d,:,f)=NewRanks(d-1,:,f);
else
for n=2:nRebDates
NewRanks(d,:,f)=RebRanks(n,:,f);
end %nRebDates
end % if statement --> After the excecution of the if statement I would like matlab to jump to d=2:nDates instead to i=2:nRebIndi.
end % nRebIndi
end % nDates
end % nFactors
  2 Comments
madhan ravi
madhan ravi on 27 Mar 2019
I have difficulty in understanding your question try "continue" instead of "break".
BdS
BdS on 27 Mar 2019
If I add "break" to my code. Then matlab jumps to the loop interation d=2:nDates. Thats good. But it is only the half solution. What I am looking for: After jumping back to d=2:nDates I want that i=2:nRebIndi continues to the next Itereation.
In other words:
the first loop iteration for nDates is 2 (as it begins by 2) and for the nRebIndi is 2 as well. After those first Interations (if I insert break), matlab jumps to the next iteration. Which is nDates 3 BUT nRebIndi iteration stays frozen at 2 (because of brerak) instead also showing 3

Sign in to comment.

Answers (1)

Stephan
Stephan on 27 Mar 2019
doc break
  1 Comment
BdS
BdS on 27 Mar 2019
Thanks for your answer.
The thing is that with "break" matlab jumps to d=2:nDates which is what I want. However, the loop i=2:nRebIndi stays frozen/terminates. And I want this loop (Iteration) to continue after getting to d=2:nDates.

Sign in to comment.

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!