# Root for loops, how to use?

**URL:** <https://root-forum.cern.ch/t/root-for-loops-how-to-use/47481>\
**Category:** Newbie\
**Tags:** root\
**Created:** [November 1, 2021, 3:43am UTC](https://root-forum.cern.ch/t/root-for-loops-how-to-use/47481 "2021-11-01T03:43:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kernelcornfarmer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/59ef9b/32.png) [@kernelcornfarmer](https://root-forum.cern.ch/u/kernelcornfarmer)\
**Post date:** [November 1, 2021, 3:43am UTC](https://root-forum.cern.ch/t/root-for-loops-how-to-use/47481/1 "2021-11-01T03:43:38Z")

</div>

hello, all I am new to root. I am trying to develop a code to calculate magnetic Jhonson noise, but I can’t seem to get my for loops to work. I am trying to convert my python code into a root code, so it’s entirely possible I’m understanding something wrong as this is my first time using root.  
I can run this macro without the for loops and I do get an output as expected (although I should find a function to get the norm instead of Mag2, but that’s a later issue), but when I try to run the macro attached below that contains nested for loops I don’t get an output or anything, the terminal just sits there as if it’s still running the code.  
Help is greatly appreciated!

 ![roothelp](https://root-forum.cern.ch/uploads/default/original/3X/5/e/5e197bacc0e7671841cd1005e8a4ca9bc1a2c128.png)

\_ROOT Version:6.24/02  
\_Platform: Windows  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [November 1, 2021, 5:35am UTC](https://root-forum.cern.ch/t/root-for-loops-how-to-use/47481/2 "2021-11-01T05:35:07Z")

</div>

In the for loop lines (i, j, k), you are missing the “=” in the last part, e.g.

```auto
  for (...; ...; i+=...)

```

Without that, the loop variables (i,j,k) are not incrementing and you are in infinite loops (print out the values of i, j and k and check this).

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 1, 2021, 4:30pm UTC](https://root-forum.cern.ch/t/root-for-loops-how-to-use/47481/3 "2021-11-01T16:30:46Z")

</div>

That’s a C/C++ question. There is many [examples/tutorials online](https://www.programiz.com/cpp-programming/for-loop)
