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

Queue: SystemVerilog Queue Example

SystemVerilog Arrays

Runnable example from the SystemVerilog Queue tutorial (SystemVerilog Queue Example)

Open in IDE
testbench.sv
module tb;
  	// Create a queue that can store "string" values
  	string   fruits[$] = '{"orange", "apple", "kiwi"};
  
	initial begin
   		// Iterate and access each queue element
  		foreach (fruits[i])
    		$display ("fruits[%0d] = %s", i, fruits[i]);
  
  		// Display elements in a queue
  		$display ("fruits = %p", fruits);
  
      	// Delete all elements in the queue
      	fruits = {};
      	$display ("After deletion, fruits = %p", fruits);
	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.