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

Exit After First Match In Priority-if

SystemVerilog Control Flow & Loops

priority if evaluates its conditions in order and executes only the first one that matches.

Open in IDE
testbench.sv
module tb;
	int x = 4;
  
  	initial begin    
      	// Exits if-else block once the first match is found
      	priority if (x == 4)
      		$display ("x is %0d", x);
      else if (x != 5)
      		$display ("x is %0d", x);
  	end
endmodule	




/*
Simulation Log:
---------------

ncsim> run
x is 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.