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

'unique' and 'priority' if-else: Exit after first match in priority-if

SystemVerilog Control Flow & Loops

Runnable example from the SystemVerilog 'unique' and 'priority' if-else tutorial (Exit after first match in priority-if)

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
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.