# Feature Suggestion: Variable Scope in Exports

**URL:** https://community.mp3tag.de/t/feature-suggestion-variable-scope-in-exports/7499
**Category:** General Discussion
**Created:** [November 20, 2008, 6:53pm UTC](https://community.mp3tag.de/t/feature-suggestion-variable-scope-in-exports/7499 "2008-11-20T18:53:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Moonbase](https://community.mp3tag.de/user_avatar/community.mp3tag.de/moonbase/32/207_2.png) [@Moonbase](https://community.mp3tag.de/u/Moonbase)
#### Post date: [November 20, 2008, 6:53pm UTC](https://community.mp3tag.de/t/feature-suggestion-variable-scope-in-exports/7499/1 "2008-11-20T18:53:23Z")

</div>

Sometimes the scope of user variables in Exports is a little awkward to use, because it is _not_ possible to use a variable that has been set previously within an _outer_ loop. For some reason, the scope of the user variables extends _outwards_, not _inwards_.

This will _not_ function (and it’d be nice if it did!):

```
$loop(%genre%)
$puts(fn,%genre%.m3u)
$loop(%_path%)
ECHO %_path% >> $get(fn)
$loopend()
$loopend()

```

_(Over-simplified code snippet, extra line feeds added for readability.)_

The variable _fn_ will be undefined within the inner _$loop(…)_.

Is it possible to change that?

---

<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: [November 21, 2008, 12:27pm UTC](https://community.mp3tag.de/t/feature-suggestion-variable-scope-in-exports/7499/2 "2008-11-21T12:27:35Z")

</div>

> [@Moonbase](#):
>
> Sometimes the scope of user variables in Exports is a little awkward to use, because it is _not_ possible to use a variable that has been set previously within an _outer_ loop. For some reason, the scope of the user variables extends _outwards_, not _inwards_. ...

Well, Moonbase, you are right to ask again for some better design and usability of user defined variables regarding their visibility in loops. I've mentioned it here and there in my postings over the years, too.  
However your example is not quite good to demonstrate the point.  
Your example is simplified like this:  
$loop(%genre%)  
'ECHO.Genre: '%genre%  
$loop(%\_path%)  
'ECHO.'%\_path%' \>\> '%genre%'.m3u'  
$loopend()  
$loopend()

DD.20081121.1425.CET

Nevertelesse, this export script demonstrates how confusing it can be.  
$loop(%genre%,1)  
'G0:'$put(fn,%genre%'.m3u')  
$loopend()  
$loop(%genre%)  
'G1:'$get(fn)  
'G2:'$put(fn,%genre%'.m3u')  
'ECHO.Genre: '%genre%  
$loop(%\_path%)  
'ECHO.'%\_path%' \>\> '$get(fn)  
$loopend()  
$loopend()

DD.20081121.1447.CET

---

<div class="post-metadata">

### Author: ![Moonbase](https://community.mp3tag.de/user_avatar/community.mp3tag.de/moonbase/32/207_2.png) [@Moonbase](https://community.mp3tag.de/u/Moonbase)
#### Post date: [November 21, 2008, 11:33pm UTC](https://community.mp3tag.de/t/feature-suggestion-variable-scope-in-exports/7499/3 "2008-11-21T23:33:08Z")

</div>

What also comes to mind is of course the apparent inefficiency in handling _loop_ conditions. On a quite simple one, like  
$loop($if(%origyear%,$div($left(%origyear%,4),10)0,$if(%year%,$div($left(%year%,4),10)0,'[unknown]')),1)which I use to provide playlists by decades, Mp3tag computes 2 hours 40 minutes for a _smaller_ collection of only 22,845 MP3s (on a 1.8 GHz XP machine; no other applications running) while eating up between 98 and 99% CPU cycles… Which makes it not really the perfect choice for performing some everyday chores (though I’d like that, of course).
