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 Loop

SystemVerilog Control Flow & Loops

A while loop counting from 0 to 4.

Open in IDE
testbench.sv
//--------------------------------------------------------------
// Author  : Admin, ChipVerify
// Website : www.chipverify.com
//--------------------------------------------------------------

module tb;
	initial begin
		int cnt = 0;
		while (cnt < 5) begin
			$display("cnt = %0d", cnt);
			cnt++;
		end
	end
endmodule

/* 
Simulation Log:
---------------
ncsim> run
cnt = 0
cnt = 1
cnt = 2
cnt = 3
cnt = 4
ncsim: *W,RNQUIE: Simulation is complete.
ncsim> exit
*/
design.sv
// Code your design here
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.