top of page

14.6. Introduction to Loops in Verilog

​

Loops provide a mechanism to execute a block of code repeatedly. In Verilog, loops are essential for testbench development, array initialization, and repetitive operations in behavioral models. Understanding when and how to use each loop type is crucial for both simulation and synthesis.

​

Types of Loops

​

Verilog provides four types of loops:

​

  • for loop - Counter-controlled iteration (most common)

​

  • while loop - Condition-controlled iteration (pre-test)

​

  • repeat loop - Fixed number of iterations

​

  • forever loop - Infinite loop (testbench only)

​

Loop Applications

Screenshot (759).png

Critical Synthesizability Note

​

âš  CRITICAL: Most loops are NOT synthesizable! Only FOR loops with CONSTANT bounds and known iteration counts can sometimes be synthesized (unrolled). while, repeat, and forever loops are TESTBENCH ONLY.

​

14.6.1. For Loop

​

14.6.2. While Loop

​

14.6.3. Repeat Loop

​

14.6.4. Forever Loop

Screenshot (760).png

Advanced techniques

For loops
 

© Copyright 2025 VLSI Mentor. All Rights Reserved.©

Connect with us

  • Instagram
  • Facebook
  • Twitter
  • LinkedIn
  • YouTube
bottom of page