# Determine the last loop inside loop?

**URL:** https://community.mp3tag.de/t/determine-the-last-loop-inside-loop/7231
**Category:** Export
**Created:** [September 23, 2008, 7:26am UTC](https://community.mp3tag.de/t/determine-the-last-loop-inside-loop/7231 "2008-09-23T07:26:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![LosMintos](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/54ee81/32.png) [@LosMintos](https://community.mp3tag.de/u/LosMintos)
#### Post date: [September 23, 2008, 7:26am UTC](https://community.mp3tag.de/t/determine-the-last-loop-inside-loop/7231/1 "2008-09-23T07:26:10Z")

</div>

Hi,

unfortunatly I do not know proper keywords for a search and maybe I'm somehow blind ☹

Consider a loop over an album in order to export the tracklisting, something like $loop(%\_filename\_ext%)

```
  $num(%track%,2) -- %title%
$loopend

```

I'm trying to execute a command only in the last loop, e.g.

```
$loop(%_filename_ext%) 
  $num(%track%,2) -- %title%
  IF this is the very last run of this loop, than do ... else nothing.
$loopend

```

I tried %\_max\_counter%, %\_total\_files% and defined a variable (puts(condition, %\_total\_files%) ... But it does not work ☹ In my case it is not a solution, to put my commands after the loop.

(By the way, it was easy to determine the first loop: $if($eql(%\_counter%,1),true,false).

Any help is appreciated. Regards, LosMintos

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [September 26, 2008, 7:54am UTC](https://community.mp3tag.de/t/determine-the-last-loop-inside-loop/7231/2 "2008-09-26T07:54:45Z")

</div>

Can't you just write the text after the $loopend command?

---

<div class="post-metadata">

### Author: ![LosMintos](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/54ee81/32.png) [@LosMintos](https://community.mp3tag.de/u/LosMintos)
#### Post date: [October 3, 2008, 2:32pm UTC](https://community.mp3tag.de/t/determine-the-last-loop-inside-loop/7231/3 "2008-10-03T14:32:04Z")

</div>

No, unfortenately not.

Long answer: The export script creates a LaTeX file. The result is a catalogue of the hole CD collection. The tracklistings of the CDs are exported in a tabular environment. By my knowlegde neither supertabular nor longtable are compatible with LaTeX's twocolumn mode or with the multicol-package (e.g. the multicols environment). That's why I create per album several tabular environments each one with a single line listing one track. Between these tabular environments a column break can occur. The last track of a tracklisting (the last tabular) shall be followed by a \bottomrule command. The \end{tabular} is created inside the loop and the \bottomrule must occur before the \end{tabular} -- but only for the last track, e.g. the last item in a loop.

```
$filename(%_workingdir%.tex)
$loop($replace(%artist%,&,\&),1)
  $loop(%album%)
    $loop(%_filename_ext%)
      \begin{tabularx}{\linewidth}{@{}r@{\quad}>{\raggedright\arraybackslash}X@{}r}$if($eql(%_counter%,1),\toprule,)
      \num{$num(%track%,2)} & $replace($replace($replace($replace(%title%,&,\&),#,\#),",''),$,\$)\dotfill & %_length%\\\\ %%HERE \bottomrule INSIDE LAST ITEM OF LOOP
      \end{tabularx}$loopend()
  $loopend()
$loopend()

```

Maybe there is a better way in LaTeX to overcome the page break limitation? Or there is a way to determine the last item of a loop inside the loop.

Any hint?

Regards, LosMintos.

---

<div class="post-metadata">

### Author: ![LosMintos](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/54ee81/32.png) [@LosMintos](https://community.mp3tag.de/u/LosMintos)
#### Post date: [January 13, 2009, 1:29pm UTC](https://community.mp3tag.de/t/determine-the-last-loop-inside-loop/7231/4 "2009-01-13T13:29:48Z")

</div>

> [@Florian](#):
>
> Can't you just write the text after the $loopend command?

Yes, now I can. I modified all the stuff after MP3Tag (in this case: LaTeX commands).

The here asked question is somehow interesting (at least for me), but so far I'm not dependent on a solution.

---

<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: [March 1, 2014, 4:47pm UTC](https://community.mp3tag.de/t/determine-the-last-loop-inside-loop/7231/5 "2014-03-01T16:47:56Z")

</div>

QUOTE (LosMintos @ Sep 23 2008, 10:26) \<{POST\_SNAPBACK}\>

... I'm trying to execute a command only in the last loop, e.g.

```
$loop(%_filename_ext%) 
  $num(%track%,2) -- %title%
  IF this is the very last run of this loop, than do ... else nothing.
$loopend

```

... (By the way, it was easy to determine the first loop: $if($eql(%\_counter%,1),true,false).  
Any help is appreciated. Regards, LosMintos

  
Better late than never ... here is an example export script ... **$filename($getEnv('USERPROFILE')'\Desktop\Export.Whatever.txt',UTF-8) $loop(%\_path%)$puts(CountMax,%\_counter%)$loopend() $loop(%\_path%) 'Item: '%\_counter%$if($eql($get(CountMax),%\_counter%),' \<-- Here is the last item.',) 'Path: '%\_path% $loopend()**

Example output ...

```
Item: 1
Path: T:\TEST\File 01.mp3

Item: 2
Path: T:\TEST\File 02.mp3

Item: 3 <-- Here is the last item.
Path: T:\TEST\File 03.mp3

```

DD.20140301.1847.CET
