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

repeat: Example #2: Wait for N Clock Cycles

SystemVerilog Control Flow & Loops

Runnable example from the SystemVerilog repeat tutorial (Example #2: Wait for N Clock Cycles)

Open in IDE
testbench.sv
module tb;
	bit clk;
	always #10 clk = ~clk;

	initial begin
		bit [2:0] num = $random;

		$display ("[%0t] Repeat loop is going to start with num = %0d", $time, num);
		repeat (num) @(posedge clk);
		$display ("[%0t] Repeat loop has finished", $time);
		$finish;
	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.