# Modify a path for each loop of the function "for"

**URL:** <https://root-forum.cern.ch/t/modify-a-path-for-each-loop-of-the-function-for/44742>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [May 6, 2021, 6:33pm UTC](https://root-forum.cern.ch/t/modify-a-path-for-each-loop-of-the-function-for/44742 "2021-05-06T18:33:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![IKoro](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@IKoro](https://root-forum.cern.ch/u/IKoro)\
**Post date:** [May 6, 2021, 6:33pm UTC](https://root-forum.cern.ch/t/modify-a-path-for-each-loop-of-the-function-for/44742/1 "2021-05-06T18:33:52Z")

</div>

Hello,

I want to save several histograms in a folder that I draw in a “for” loop. The histograms plot well but when I try to save them using print, the histogram from the previous loop erases the histogram from the next loop. In the end I have more than the histograms from my last one in my files. I don’t know how to modify my path for each loop made.

for (int j = 300; j \<= 305; j++ )

{  
… I created a canvas and insert the data into hist …

hist-\>Draw();  
c1-\>Print("/home/dupuy/Documents/code\_dupuy/Exercices/Image/1.png");  
}

i want to create a path using the j.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 6, 2021, 6:36pm UTC](https://root-forum.cern.ch/t/modify-a-path-for-each-loop-of-the-function-for/44742/2 "2021-05-06T18:36:49Z")

</div>

`c1->Print(TString::Format("/home/dupuy/Documents/code_dupuy/Exercices/Image/%d.png", j));`

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 6, 2021, 6:37pm UTC](https://root-forum.cern.ch/t/modify-a-path-for-each-loop-of-the-function-for/44742/3 "2021-05-06T18:37:56Z")

</div>

Hi,  
try

```auto
c1->Print(Form("/home/dupuy/Documents/code_dupuy/Exercices/Image/%03i.png", j));

```

---

<div class="post-metadata">

**Author:** ![IKoro](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@IKoro](https://root-forum.cern.ch/u/IKoro)\
**Post date:** [May 6, 2021, 6:42pm UTC](https://root-forum.cern.ch/t/modify-a-path-for-each-loop-of-the-function-for/44742/4 "2021-05-06T18:42:57Z")

</div>

Thank you so much, it works !!
