# repeat vs for loop control variable

**URL:** <https://verificationacademy.com/forums/t/repeat-vs-for-loop-control-variable/51647>\
**Category:** SystemVerilog\
**Created:** [May 25, 2026, 12:44pm UTC](https://verificationacademy.com/forums/t/repeat-vs-for-loop-control-variable/51647 "2026-05-25T12:44:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saharsh23](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/b9bd4f/32.png) [@Saharsh23](https://verificationacademy.com/forums/u/Saharsh23)\
**Post date:** [May 25, 2026, 12:44pm UTC](https://verificationacademy.com/forums/t/repeat-vs-for-loop-control-variable/51647/1 "2026-05-25T12:44:58Z")

</div>

How `repeat` and `for` loops handle loop variables internally in SystemVerilog?

Example:

```auto
int n = 5;

repeat(n) begin
  n++;
end

for (int n = 0; n < 6; n++) begin
  n++;
end

```

`repeat(n)` seems to evaluate `n` only once, while `for` reevaluates the condition every iteration.

How does the simulator handle these internally?

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [May 26, 2026, 7:34pm UTC](https://verificationacademy.com/forums/t/repeat-vs-for-loop-control-variable/51647/2 "2026-05-26T19:34:19Z")

</div>

The [IEEE 1800-2023 SystemVerilog LRM](https://ieeexplore.ieee.org/document/10458102) explicitly defines this behavior. The LRM mandates that the `repeat(expression)` construct evaluates the expression only once and then use a hidden counter to control the number of loop iterations.
