I am using below code-
module fork_try;
reg a,b;
initial begin
fork:fork2
begin
#2 $display("2.done and t5 and time %d",$time);
b=1;
end
begin
for(a=0;a<4;a++) //why for loop is getting executed again and again?
begin
#2 b=a; $display("b is %d and time %d",b,$time);
if(b==2)
begin $display("a is %d",a);break;
end
end
///if(b==1)
// continue; //continue statements only allowed within loops //continue statement inside a fork...join cannot be used to control loop outside the fork...join
$display("5.done and t15 and time %d",$time);
end
join_any
end//initial
endmodule
During simulation , i am getting following result-
2.done and t5 and time 2
b is 0 and time 2
b is 1 and time 4
1.done and t20 and time 5
b is 0 and time 6
b is 1 and time 8
b is 0 and time 10
b is 1 and time 12
b is 0 and time 14
b is 1 and time 16
b is 0 and time 18
until simulation ends.
Why fork is not getting finished. If i give continue instead of break, i am observing the same behaviour.