SystemVerilog break and continue

 break 


Execution of break statement leads to end of the loop.

  Example-1:  

In below example,
when the loop value equals to 4, break is called this leads to end of the loop.

module break_in_loop;

  initial begin
    $display("-----------------------------------------------------------------"); 

    for(int i=0;i<8;i++) begin
      $display("\tValue of i=%0d",i);
      if(i == 4) begin
        $display("\tCalling break,");
        break;
      end 
    end  

    $display("-----------------------------------------------------------------");
  end

endmodule

  Simulator output:  

-----------------------------------------------------------------
      Value of i=0
      Value of i=1
      Value of i=2
      Value of i=3
      Value of i=4
      Calling break,
-----------------------------------------------------------------
Execute the above code on 


 continue 

Execution of continue statement leads to skip the execution of statements followed by continue and jump to next loop or iteration value.

  Example-1:  

In below example,
when ever the loop value is with in 3 to 6, continue statement will be executed, this leads to skip the execution of display statement after the continue.

module continue_in_loop;

  initial begin
    $display("-----------------------------------------------------------------");
 
    for(int i=0;i<8;i++) begin     

      if((i > 2) && (i < 7))begin
        $display("\t\tCalling continue,");
        continue;
      end   

      $display("\t\tAfter Continue\t:: Value of i=%0d",i);
    end

    $display("-----------------------------------------------------------------");

  end

endmodule


  Simulator output:  

-----------------------------------------------------------------
After Continue :: Value of i=0
After Continue :: Value of i=1
After Continue :: Value of i=2
Calling continue,
Calling continue,
Calling continue,
Calling continue,
After Continue :: Value of i=7
-----------------------------------------------------------------
Execute the above code on