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

Do While Loop

SystemVerilog Control Flow & Loops

A do...while loop that still executes its body once even though the while condition is false from the start.

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

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

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