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

forever loop: Example: Clock Generation

SystemVerilog Control Flow & Loops

Runnable example from the SystemVerilog forever loop tutorial (Example: Clock Generation)

Open in IDE
testbench.sv
module tb;
  bit clk;                     // 2-state, starts at 0

  initial begin
    forever #5 clk = ~clk;     // toggle every 5 ns: 10 ns period (100 MHz)
  end

  initial begin
    #50 $finish;               // the clock loop never ends, so stop here
  end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.