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

foreach loop: Example #2: Multidimensional Arrays

SystemVerilog Control Flow & Loops

Runnable example from the SystemVerilog foreach loop tutorial (Example #2: Multidimensional Arrays)

Open in IDE
testbench.sv
module tb;
  int md_array [5][2] = '{'{1,2}, '{3,4}, '{5,6}, '{7,8}, '{9,10}};

  initial begin
    // i walks the first dimension (outer), j walks the second (inner)
    foreach (md_array[i, j])
      $display ("md_array[%0d][%0d] = %0d", i, j, md_array[i][j]);
  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.