Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

'break' and 'continue': break in Nested Loops

SystemVerilog Control Flow & Loops

Runnable example from the SystemVerilog 'break' and 'continue' tutorial (break in Nested Loops)

Open in IDE
testbench.sv
module tb;
  initial begin
    for (int row = 0; row < 3; row++) begin
      for (int col = 0; col < 3; col++) begin
        if (col == 1)
          break;                          // leaves the inner (col) loop only
        $display ("row %0d col %0d", row, col);
      end
    end
  end
endmodule
// Prints: row 0 col 0, row 1 col 0, row 2 col 0
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.