top of page

14.6.2. While Loop

The while loop is a condition-controlled loop that executes as long as the specified condition is true. It is a PRE-TEST loop (condition checked before execution) and is NOT synthesizable.

Syntax and Structure

Verilog

Characteristics

  • Condition is checked BEFORE each iteration

  • If condition is false initially, loop never executes

  • Iteration count unknown until runtime

  • NOT synthesizable (testbench only)

  • Must have timing control to avoid infinite zero-time loop

Basic Examples

Verilog

While Loop vs For Loop Equivalence

Verilog

Common While Loop Patterns

Verilog

Critical: Avoiding Infinite Loops
 

⚠ DANGER: While loops without timing controls will create INFINITE ZERO-TIME LOOPS that hang the simulator!

Verilog

For loop

Repeat loop
 

  • Instagram
  • Facebook
  • Twitter
  • LinkedIn
  • YouTube

Connect with us

bottom of page