Clarification on $if vs $if2?

Tags: #<Tag:0x00007f7d026ffaa0> #<Tag:0x00007f7d026ff4b0>

Starting with ‘thing’


$if(If,then, else)

If this, you get that, if not, something_else

So you add either that or something_else to %thing%

…or you still have just %thing%


You either get %thing%with then added to it, or you still just have %thing%.


If this, is that, or the_other_thing, or the greatest_thing.

…so you now have %thing% plus whichever one of those got on the bus first.

…or just still just have %thing%

Would this:

$if($eq(%thing%,1), we get %thing%
…or Nothing [Done]
. . .$if($eq(%that%,1), we get %that%%thing%
or Just %thing% [Done]
. . . . $if($eq(%messy%,1), we get %that%%messy%%thing%
or Just %that%%thing% [Done]
. . . . . $if($eq(%green%,1), we get %that%%messy%%green%%thing%
Just %that%%messy%%thing%
. . . . . . $if($eq(%red%,1), we get %that%%red%%messy%%green%%thing%)
or Just %that%%messy%%green%%thing%
. . . . . . . and we're in 4 deep.

. . . . . . . . . $if($eq(%gross%,1),%that%%messy%%green%%gross%%thing%)
. . . . . . . . . $if($eq(%sticky%,1),%that%%messy%%green%%sticky%%thing%)
. . . . . . . . . $if($eq(%filthy%,1),%that%%messy%%green%filthy%%thing%)



Just writing that was crazy. I’ve got something wonky going on and I’m sure it’s related to ‘if’ depth, but I can’t quite find it.

I’m not really sure what you’re trying to do here, so I’ll start by trying to boil it down to a simpler example.

So just using a three level $if statement:


If all three variables equal 1, then the output of this would be “111”.
I any of the variables is not equal to 1, the output would be nothing, because the third if statement is the only one with any output.

I’m not sure what the “we get…” comments in your example mean.

To clarify the $if statement, using your first example, and starting with the word “thing” instead of the variable thing:

Thing$if($eq(%control%,1), then, else)

The output for this, if %control% equals 1 is:
Thing then

If %control% does not equal 1:
Thing else


I’m trying to get a grasp on primarily is the ‘else’ part of all this, and the embedding with even embedded conditionals plus the $if(,,) vs $if(,) That trailing comma, vs not having it.

Would $if(this,that,) and $if(this,that) result in the same thing, just the former being sloppy?

((((),), etc.

So then could that successive set of starting at the second $if be done with an $if2 instead since the result is going to be the first one met and check against no more in that specific order?
…unless it reaches the second to the last $if, and only then would it compare against that one last $if

It’s supposed to be: if the first $if is true, it’s going to check for which of the next several conditions it is, as it can only be one, but if it’s the last one, is it also something else?

It’s the same result. If the else part is not set or empty the $if will return an empty string.

I am not sure how you mean that, but $if2 is something different than $if. While $if is basically the typical conditional “if-then-else” logic you know from other programming languages, $if2 is a function which returns the first non-empty argument.

The typical usage is for something like e.g. $if2(%albumartist%,%artist%), which will give the albumartist if set, otherwise the artist.

Combined with $if it kind of ends up being a $or. The two $if statements below are basically equivalent: