# Unexpected If-Then Behavior in an Export Loop

**URL:** https://community.mp3tag.de/t/unexpected-if-then-behavior-in-an-export-loop/16037
**Category:** Support
**Created:** [August 22, 2014, 9:08pm UTC](https://community.mp3tag.de/t/unexpected-if-then-behavior-in-an-export-loop/16037 "2014-08-22T21:08:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rko31415](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@rko31415](https://community.mp3tag.de/u/rko31415)
#### Post date: [August 22, 2014, 9:08pm UTC](https://community.mp3tag.de/t/unexpected-if-then-behavior-in-an-export-loop/16037/1 "2014-08-22T21:08:29Z")

</div>

Three files attached:

1. .mte (export config) file
2. .txt export output file
3. sample .mp3 files

I have titles formatted WW.LL Text ... where WW = week number and LL = lesson number (Coursera lectures)  
I want to check these for numbering gaps.

I want to only show "missing" episodes when there's a gap in lesson numbers, not when a week changes. So in the sample .mp3 files below I would only show a missing episode at 04.04

Beatles - 03.06 She.mp3  
Beatles - 03.07 Loves.mp3  
Beatles - 03.08 Me.mp3  
Beatles - 04.01 Yah.mp3  
Beatles - 04.02 Nah.mp3  
Beatles - 04.04 Blah.mp3  
Beatles - 04.05 Ohhh.mp3

Below is the .mte file. The error comes in the first if statement ... $puts(LessonCount,$fmtNum($mid(%title%,4,2))) is getting invoked as though the if statement weren't even there ... both the TRUE and FALSE conditions of the if statement are being processed. LessonCount is being set to the current lesson number even when the week has not iterated.

$filename($getEnv('USERPROFILE')'\desktop\Numbering-Gaps.txt',UTF-8)$loop(%album%)$loop(%title%)  
$puts(CurrWeek,$fmtNum($left(%title%,2)))  
$if($eql($get(LastWeek),$get(CurrWeek)),$puts(LessonCount,$add(1,$fmtNum($get(LessonCount)))),$puts(LastWeek,$get(CurrWeek))$puts(LessonCount,$fmtNum($mid(%title%,4,2))))  
$if($eql($get(LessonCount),$fmtNum($mid(%title%,4,2))),' OKAY: ','# Missing Track: '$puts(LessonCount,$fmtNum($mid(%title%,4,2)))) %album% %title%  
$loopend()  
$loopend()

Thoughts?

[\_\_.\_\_\_NumberingGaps.mte](https://community.mp3tag.de/uploads/default/original/2X/2/234a001f472a9a9ac01361caa7779d7a75e4a714.mte) (834 Bytes)

[Numbering\_Gaps.txt](https://community.mp3tag.de/uploads/default/original/2X/4/4c75c798bcca99c1f44e3730670bd5176f9f80b0.txt) (248 Bytes)

[Beatles.rar](https://community.mp3tag.de/uploads/default/original/2X/a/a137550bb218c07cb10a80b6faacc86bd698c768.rar) (136 KB)

---

<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: [August 23, 2014, 4:35am UTC](https://community.mp3tag.de/t/unexpected-if-then-behavior-in-an-export-loop/16037/2 "2014-08-23T04:35:21Z")

</div>

> [@rko31415](#):
>
> ... The error comes in the first if statement ... Thoughts?

Have a look there ...  
[Export, $Puts() is executed always](https://community.mp3tag.de/t/14084/2)  
You have to modify the $if statements, because $put/$puts does not work within $if expression.

DD.20140823.0835.CEST

---

<div class="post-metadata">

### Author: ![rko31415](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@rko31415](https://community.mp3tag.de/u/rko31415)
#### Post date: [August 24, 2014, 8:34pm UTC](https://community.mp3tag.de/t/unexpected-if-then-behavior-in-an-export-loop/16037/3 "2014-08-24T20:34:35Z")

</div>

Thanks. Your assistance in this forum has been exemplary.

Your answer is not fully correct, and I supply a clarification for future forum readers.

You can use $puts within an $if statement, just not more than one at a time. Below is a functioning example.

This Export configuration code finds numbering gaps across multiple albums with titles of the format '##.## text'

$filename($getEnv('USERPROFILE')'\desktop\Numbering-Gaps.txt',UTF-8)  
$loop(%album%)$loop(%title%)  
$puts(LessonCount,$add(1,$get(LessonCount)))  
$if($or($eql($fmtNum($mid(%title%,4,2)),$get(LessonCount)),$neql($fmtNum($left(%title%,2)),$get(LastWeek))),' OKAY: ','# Missing Track: '$puts(LessonCount,$mid(%title%,4,2)))  
$puts(LastWeek,$fmtNum($left(%title%,2)))%album% %title%  
$loopend()$puts(LastWeek,$left(%title%,2))  
$loopend()

Cheers

---

<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: [August 25, 2014, 6:28am UTC](https://community.mp3tag.de/t/unexpected-if-then-behavior-in-an-export-loop/16037/4 "2014-08-25T06:28:10Z")

</div>

> [@rko31415](#):
>
> ... Your answer is not fully correct, and I supply a clarification for future forum readers.  
> You can use $puts within an $if statement, just not more than one at a time. ...

Thanks for the info ... I will have a look into.  
Maybe in the meantime there was a silent error repair in the Mp3tag export scripting language?

BTW ... instead of "$fmtNum($mid(%title%,4,2)" ...  
you may use "$num($mid(%title%,4,2),1)"

DD.20140825.1028.CEST

---

<div class="post-metadata">

### Author: ![rko31415](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/r/f19dbf/32.png) [@rko31415](https://community.mp3tag.de/u/rko31415)
#### Post date: [September 3, 2014, 1:34pm UTC](https://community.mp3tag.de/t/unexpected-if-then-behavior-in-an-export-loop/16037/5 "2014-09-03T13:34:38Z")

</div>

I went to clone the above export configuration for other purposes and discovered that the statement: $puts(LessonCount,$mid(%title%,4,2)) could just as well have been outside the if-then loop. The above export configuration still works for its original intention (finding gaps), but the $puts gets fired off every iteration of the loop whether or not the if-then condition is met.

... so for now the moderator's original feedback stands:

you cannot use $puts within the conditionals of an if-then.

Sorry for any confusion.

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [February 9, 2026, 12:25pm UTC](https://community.mp3tag.de/t/unexpected-if-then-behavior-in-an-export-loop/16037/6 "2026-02-09T12:25:12Z")

</div>


