Break for loop of virtual sequence on error response in sequence

Hi,

I have for loop inside virtual sequence. I want to break for loop when sequence got error response from driver.

Virtual sequence snippet:

virtual task body();

for(int i=0;i<100;i++)
begin
fork
read.start(read_sqr);
join
end
endtask

Read sequence snippet:

virtual task body();

fork
begin
start_item(Tr);
Tr.randomize();
finish_item(Tr);
end
begin
get_response(Tr);
end
join
end
endtask

virtual task body();
...
for(int i=0;i<100;i++)
  begin
   fork
     read.start(read_sqr);
   join
  end
endtask

//Read sequence snippet:

virtual task body();
...
  fork
    begin
      start_item(Tr);
      Tr.randomize(); 
      finish_item(Tr);
    end
    begin
      get_response(Tr);
    end
  join 

endtask

I don’t see any advantage of using fork…join in read sequence. If your requirement is just to break the loop after receiving the error response(you didn’t mentioned of spawning of read cmds so lets not consider it)

virtual task body();
...
for(int i=0;i<100;i++)
  begin
     read.start(read_sqr);
     if(read.error_rsp == 1) begin
       //Display Error
       break;
     end
  end
endtask

//Read sequence snippet:

virtual task body();
  bit error_rsp=0;
...
    begin
      start_item(Tr);
      Tr.randomize(); 
      finish_item(Tr);
      get_response(Tr);
      error_rsp = Tr.error_flag //as per your implementation.
    end
endtask