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

SystemVerilog Control Flow & Loops

A while loop whose condition is already false on entry, so the body never runs.

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

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

/* 
Simulation Log:
---------------
ncsim> run
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.