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

When Used In Conditional Statements

SystemVerilog Constraints

The inside operator used in a ternary and in if/else to test whether a random value falls in the range 4 to 9.

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

module tb;
	bit [3:0] 	m_data;
	bit 		flag;
	
	initial begin
		for (int i = 0; i < 10; i++) begin
			m_data = $random;
			
			// Used in a ternary operator
			flag = m_data inside {[4:9]} ? 1 : 0;
			
			// Used with "if-else" operators
			if (m_data inside {[4:9]})
				$display ("m_data=%0d INSIDE [4:9], flag=%0d", m_data, flag);
			else 
				$display ("m_data=%0d outside [4:9], flag=%0d", m_data, flag);
			
			
		end
	end
endmodule
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.