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

while and do-while loop: Example #1: while Loop

SystemVerilog Control Flow & Loops

Runnable example from the SystemVerilog while and do-while loop tutorial (Example #1: while Loop)

Open in IDE
testbench.sv
module tb;
	initial begin
		int cnt = 0;
		while (cnt < 5) begin
			$display("cnt = %0d", cnt);
			cnt++;
		end
	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.