i have the following code which runs infinitely when executed. it is fine if i remove the CONTINUE statement. however, with the CONTINUE statement the problem arises. the code is
Bn_x=zeros (length(pu_arrival), 1); Bn_x(1)=6;
Br_x=zeros (length(pu_arrival), 1); Br_x(1)=2;
jn1= zeros (length(pu_arrival), 1); jn1(1)=3;
in=zeros (length(pu_arrival), 1);
jn2= zeros (length(pu_arrival), 1); jn2(1)=3;
jr1=zeros (length(pu_arrival), 1); jr1(1)=1;
ir=zeros (length(pu_arrival), 1);
jr2=zeros (length(pu_arrival), 1); jr2(1)=1;
numb_chan_idle_N=0;
numb_chan_idle_R=0;
for i=2:24 %length(pu_arrival)
if rem(i,2)==0
[Bn_x,Br_x]=failure3(numb_chan_idle_N,numb_chan_idle_R,in,jn1,jn2,ir,jr1,jr2,Bn_x,Br_x,i);
continue
end
end
%%%%%%%% The called function %%%%%%%%%%%%
function [Bn_x,Br_x] =failure3(numb_chan_idle_N,numb_chan_idle_R,in,jn1,jn2,ir,jr1,jr2,Bn_x,Br_x,i)
temp=0;
while temp<1
x=randi([1 6]);
if x==1
if in(i-1)>0
temp=temp+1;
end
elseif x==2
y=randi([1 2]);
if y==1
if jn1(i-1)>0
temp=temp+1;
end
elseif y==2
if jn2(i-1)>0
temp=temp+1;
end
end
elseif x==3
if ir(i-1)>0
end
elseif x==4
y=randi([1 2]);
if y==1
if jr1(i-1)>0
temp=temp+1;
end
elseif y==2
if jr2(i-1)>0
temp=temp+1;
jr2(i)=jr2(i-1)-1;
Br_x(i)=Br_x(i-1)-1;
else
fprintf('JR2 destined to fail but it is already=%d\n', jr2(i-1))
continue
end
end
elseif x==5
if numb_chan_idle_N>0
temp=temp+1;
end
elseif x==6
if numb_chan_idle_R>0
temp=temp+1;
end
end
end
end
I want controller to go back to the FOR loop after IF condition satisfies and its inner statement executes. However, the controller never comes out. I can't figure out what is wrong with the code.