# Export: Use of $put/$get across nested loops?

**URL:** https://community.mp3tag.de/t/export-use-of-put-get-across-nested-loops/18725
**Category:** Support
**Created:** [February 19, 2017, 3:07pm UTC](https://community.mp3tag.de/t/export-use-of-put-get-across-nested-loops/18725 "2017-02-19T15:07:32Z")
**Posts on this page:** 1
**Showing post:** 11

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [February 25, 2017, 5:36am UTC](https://community.mp3tag.de/t/export-use-of-put-get-across-nested-loops/18725/11 "2017-02-25T05:36:22Z")

</div>

> [@mls](#):
>
> Hello, I found some slightly dated entries in the forums that stated the use of user variables created by $put could not be referenced within a "nested" (or "sub") loop. Can someone please tell me if this restriction is still correct? ...

I think I have all said and written about the visibility of $put/$puts some time ago.  
There you can find a mte script, which demonstrates the behaviour ...  
[Check if field value is identical for all selected tracks](https://community.mp3tag.de/t/13244/3)

Maybe I'm blind to this thread problem because I've been taking such a long break with Mp3tag export scripting, but a further test on Mp3tag v2.81 makes me fear that something is wrong.

Run this export script and check the result ...

**$filename($getEnv('USERPROFILE')'\Desktop\LoopCheck.txt',UTF-8) '20170225.Mp3tag.LoopCheck' $loop(1,1)'aanum='$put(aanum,0)$loopend() 'aanum='$get(aanum)' ???' '---' '#loop albumartist'$loop(%ALBUMARTIST%) 'aaname='%ALBUMARTIST% 'aanum='$put(aanum,$add(1,$get(aanum))) '#loop album'$loop(%ALBUM%) 'aaname='%ALBUMARTIST% 'aanum='$get(aanum) 'album='%ALBUM% $loopend()'#loopend album' $loopend()'#loopend albumartist'**

I did the test on 3 files, having fields and values ...  
ALBUMARTIST=AlbumArtist\_1; ALBUM=Album\_1\_1  
ALBUMARTIST=AlbumArtist\_2; ALBUM=Album\_2\_1  
ALBUMARTIST=AlbumArtist\_2; ALBUM=Album\_2\_2

... and got this output ...

**20170225.Mp3tag.LoopCheck aanum=0 aanum=2 ??? --- #loop albumartist aaname=AlbumArtist\_1 aanum=1 #loop album aaname=AlbumArtist\_1 aanum=0 album=Album\_1\_1 #loopend album aaname=AlbumArtist\_2 aanum=2 #loop album aaname=AlbumArtist\_2 aanum=1 album=Album\_2\_1 aaname=AlbumArtist\_2 aanum=1 album=Album\_2\_2 #loopend album #loopend albumartist**

Have a look at the values of variable aanum, ...  
there might be different failures, ...  
especially a calculation failure of -1 when the variable is read within another loop construct.

DD.20170225.1028.CET

I did another test with a modified export script ...  
... which creates a better result ...

**$filename($getEnv('USERPROFILE')'\Desktop\LoopCheck.2.txt',UTF-8) '20170225.Mp3tag.LoopCheck.2' $loop(0)'aanum='$put(aanum,0) 'aanum='$get(aanum)''$if($eql(0,$get(aanum)),'','') '---' '#loop albumartist'$loop(%ALBUMARTIST%) 'aaname='%ALBUMARTIST% 'aanum='$put(aanum,$add(1,$get(aanum))) '#loop album'$loop(%ALBUM%) 'aaname='%ALBUMARTIST% 'aanum='$add(1,$get(aanum)) 'album='%ALBUM% $loopend()'#loopend album' $loopend()'#loopend albumartist' $loopend()**

... and got this output ...

**20170225.Mp3tag.LoopCheck.2 aanum=0 aanum=0 --- #loop albumartist aaname=AlbumArtist\_1 aanum=1 #loop album aaname=AlbumArtist\_1 aanum=1 album=Album\_1\_1 #loopend album aaname=AlbumArtist\_2 aanum=2 #loop album aaname=AlbumArtist\_2 aanum=2 album=Album\_2\_1 aaname=AlbumArtist\_2 aanum=2 album=Album\_2\_2 #loopend album #loopend albumartist**

DD.20170225.1655.CET

---

_[View the full topic](https://community.mp3tag.de/t/export-use-of-put-get-across-nested-loops/18725)._
