# Using fork join\_none within for loop in module v/s class

**URL:** <https://verificationacademy.com/forums/t/using-fork-join-none-within-for-loop-in-module-v-s-class/50118>\
**Category:** SystemVerilog\
**Tags:** fork-join\_none, SystemVerilog, for-loop-fork-join\_none\
**Created:** [April 26, 2025, 6:53pm UTC](https://verificationacademy.com/forums/t/using-fork-join-none-within-for-loop-in-module-v-s-class/50118 "2025-04-26T18:53:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arshi582](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/c77e96/32.png) [@arshi582](https://verificationacademy.com/forums/u/arshi582)\
**Post date:** [April 26, 2025, 6:53pm UTC](https://verificationacademy.com/forums/t/using-fork-join-none-within-for-loop-in-module-v-s-class/50118/1 "2025-04-26T18:53:32Z")

</div>

Hi,  
I am trying the following code

```auto
class A;
  
  task body(); // Class suboutines are automatic by default

    for( int i = 0 ; i < 4 ; i++) begin
      int j = i ; // Is 'j' automatic by default as 'body()' is automatic ?
      fork
        $write("%0d_",j);
      join_none        
    end          
  endtask  
  
endclass  
  

module tb;
  
  A a1; 
  
  /*initial begin :B1
    for( int i = 0 ; i < 4 ; i++) begin
      int j = i ; // Is 'j' static by default as 'initial' is static ?
      fork
        $write("%0d_",j);
      join_none        
    end          
  end*/  
  
  initial begin:B2
    a1 = new();
    a1.body();    
  end  
  
endmodule

```

I have a few questions on working of above code

(Q1) Given that the body() task is automatic by default, is the variable ‘j’ automatic by default as well ?

(Q2) Does the LRM define the exact output for the for-loop within body() ?  
Some tools give output as **0\_1\_2\_3\_** whereas some give output as **3\_2\_1\_0\_**

(Q3) On uncommenting B1, why do I observe a compilation error for statement **int j = i ;**  
As initial is a static procedural block, would ‘j’ be static by default ?  
I notice that on re-writing it as **automatic int j = i;** the compilation issue is resolved  
With the explicit automatic declaration, the output differs across tools ( similar to Q2 )

Thanks in advance,  
Arshi

---

<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:** [April 27, 2025, 12:10am UTC](https://verificationacademy.com/forums/t/using-fork-join-none-within-for-loop-in-module-v-s-class/50118/2 "2025-04-27T00:10:58Z")

</div>

(A1) Correct.

(A2) The LRM section _4.7 Nondeterminism_ explicitly defines the execution order of statements in concurrent processes is nondeterministic.

(A3) See: [Function arguments not initializing variable inside the body - #2 by dave\_59](https://verificationacademy.com/forums/t/function-arguments-not-initializing-variable-inside-the-body/31889/2)
