Nesting Conditionals Syntax help

Newby question. I’m looking for help with nesting conditionals (not serial). I’ve search through the community and can’t seem to find it.

In general, basic conditional syntax is as follows:

$#tag#==false?100:0$ therefore the standard IF ? THEN : ELSE

I would like to nest conditionals within conditionals. For example, below are increasing complexities. Please ignore the () as I’m using them to visually identify the parts of the conditional more easily.

Example 1: Additional conditional in the ELSE section.

$#tag#==false?100:($#tag#==false?#DD#*4:36$)$

Example 2: Additional conditionals in the THEN and ELSE sections.

$#tag#==false?($#tag#==false? 8+1:#DOW#*60$):($#tag#==false?#DD#*4:36$)$

Example 3: Conditional buried within the IF section as well.

$($#tag#==false?#tag#/2,0$)==false?($#tag#==false? 8+1:#DOW#*60$):($#tag#==false?#DD#*4:36$)$

As you can see I’m burying a conditional each part of the IF THEN ELSE sections. Looking for the syntax to do nested conditionals.

Another question as it relates to conditional.

Starting with the basic condition again:

$#tag#==false?100:0$

Can I do additional math with the result of the conditional?

$#tag#==false?100:0$*10

In this example, if the result of the conditional is 100, I would like to multiple 100 by 10.

Are these possible? And if so, what is the syntax?

Is there a limit to the number of buried conditionals within facer?

Thanks in advance.

3 Likes

Yes, it can be done. Here a sample to make day of the week with 2 letters:

$#DOW#=0?SU:$$#DOW#=1?MO:$$#DOW#=2?TU:$$#DOW#=3?WE:$$#DOW#=4?TH:$$#DOW#=5?FR:$$#DOW#=6?SA:$

I don’t know about a limit, I have seen some extreme stuff (search for zodia in the community).

4 Likes

I think we are calling those Serial . I have one that covers the Roman numerals for battery power from NULA to C . I think @ghsu.ca is asking about nested conditionals . A bit beyond me at the moment .

2 Likes

Not sure you can do more than 2.

As far as I understod, it is limited to 2 conditions using “&&” or “||” as operand.

You could overlay a few of them and hide those depending on a 3rd condition.

4 Likes

Yes nesting more than two becomes unreliable.

3 Likes

This is in docs . I think it need testing they did not offer an example . I know I have seen some nested stuff but it is finding it that is the issue . I usually put the second condition in another field . Ending up wit Stuff Zero pixels high . But if it works it works .
.

4 Likes

Remember!!!
If everything there is numeric only you can get as complex as you want.
It is only when you wrap your condition as $[MyLogic]$ are you constrained by the rules in the above documentations.
Where no strings are needed, in or out, then the following is absolutely fine to make the unit of minutes drop to or from the frame on the first second of each minute:
(#Dm#%10%2==1&&#Ds#>0?280:#Dm#%10%2==0&&#Ds#>0?380:#Dm#%10%2==1?380-#DWFSS#*16.666666:280-#DWFSS#*16.666666)
Said it worked. Not that it was pretty.

2 Likes

Ok, here is how I interprete Tom’s example.

I see the $$, does this imply as Russell suggest a serial structure or nested?

Facer would execute the first if, then execute the 2nd if and so on?

If it is executing each of the if no matter what, then that would imply serial.

If it fails at any spot and drop out of the middle of this line, then that may imply nesting.

I don’t understand the :$$ means. my understanding is that the $ at the start and end is the complete conditional. starting $ and ending $. so would the two $$ mean that the first $ ends the first conditional and second $ starts the next conditional? This seems to imply serial structure?

4 Likes

$[Condition1]?[Output1]:nothing$$[Condition2]?[Output2]:nothing$ can be read as
$[Condition1]?[Output1]:nothing$
$[Condition2]?[Output2]:nothing$

I often build them that way for visibility in a text editor then remove the carriage returns

4 Likes

Does your example have accurate syntax? I don’t see $ signs.

Should there be $ signs? If not then that is great.

Are () same as $ signs?

2 Likes

So that is serial?

2 Likes

You only need $ when there are string values. If only numbers you are unconstrained. I took that from a whole watch built on that principal of unlimited ternary conditions:
This is it working:

3 Likes

Fabulous. My calculations and conditionals are all numeric. I will look at your examples.

Can one place () as much as one wants to? Just to separate things more visually?

4 Likes

AS I see it normally after the colon we would have the else operation . In these serial Complications the else is ignored . As I remember if you put anything there even a Zero the series will not work .
So the series is built with single If/Test with one resulting operation only . the $$ is just the end of one contritional and the beginning of the next . If you put spaces there stuff starts moving mysteriously .

$#DOW#=0?SU:$$#DOW#=1?MO:$

2 Likes

Some want to, I prefer not to. Mathemeatically, and programatically it does not affect the functionality but I find
(1+2)*3 much easier to read than (((1)+(2))*(3))

If it works then go with what you find easiest to maintain and get a decent, bracket matching notepad like notepad++ or UltraEdit

3 Likes

ok. off to the woods I go. Thanks Tom, Thomas, Rob and Russell.

I am trying to adjust my UTC for daylight savings. I have the formula working in excel and now trying to translate it to Facer instructions. See how far I can get. Cross fingers.

4 Likes

I’m building my formula, step by step, component by component and with brackets imbedded as i go along. Need () else it’s just unreadable.

3 Likes

I have Expressions as a folder in Onedrive/Resources/Facer that contains text files such as:
StringCats.txt

Letters of the month
M1 Text
$#DM#==1?J:$$#DM#==2?F:$$#DM#==3||#DM#==5?M:$$#DM#==4||#DM#==8?A:$$#DM#==1||#DM==7?J:$$#DM#==9?S:$$#DM#==10?O:$$#DM#==11?N:$$#DM#==12?D:$
M2 Text
$#DM#==1||#DM#==3||#DM#==5?a:$$#DM#==2||#DM#==9||#DM#==12?e:$$#DM#==4?p:$$#DM#==6||#DM#==7||#DM#==8?u:$$#DM#==10?c:$$#DM#==11?o:$
M3 Text
$#DM#==1||#DM#==6?n:$$#DM#==2?b:$$#DM#==3||#DM#==4?r:$$#DM#==5?y:$$#DM#==6?n:$$#DM#==7?l:$$#DM#==8?g:$$#DM#==9?p:$$#DM#==10?t:$$#DM#==11?v:$$#DM#==12?c:$

Or transitions Face.txt

HOUR-L-Text
(floor(#Db#/10))
Hour-L-TransMask FILL
(#Dm#==59&&#Ds#==59&&((#DTIMEFORMAT#=12&&(#DH#==0||#Dh#==9))||(#DTIMEFORMAT#=24&&(#DH#=23||#DH#==9||#DH#==19)))?(#DWFSS#-#DWFS#)*0.1666666:#Dm#==0&&#Ds#==0&&((#DTIMEFORMAT#=12&&(#Dh#==1||#Dh#==10))||(#DTIMEFORMAT#=24&&(#DH#=0||#DH#==10||#DH#==20)))?1-#DWFSS#*0.1666666:0)

HOUR-R-Text
(#Db#%10)
Hour-R-TransMask FILL
(#Dm#==59&&#Ds#==59?(#DWFSS#-#DWFS#)*0.1666666:#Dm#==0&&#Ds#==0?1-#DWFSS#*0.1666666:0)
*OLD*Hour-R-TransBlind HEIGHT
(#Dm#==59&&#Ds#==59?(#DWFSS#-#DWFS#)*2.5:#Dm#==0&&#Ds#==0?15-#DWFSS#*2.5:0)
3 Likes

Serial is only needed for $[Logic]$ expressions as they cannot, in Facer handle complex nested statements so you take each possible condition in turn, episode 1,2,3,4,5 (not going to get into up to 90s computer serial I’d then have to explain parallel).
So, Monday Ep1 or nothing. Tuesday Ep2 or nothing.
Mess up your equality statements and you miss one or get 2 episodes in a row.

3 Likes

Here is different topic.

The MOD tag. People use MOD(A%N).

Example. Mod (20%7), the answer should 6. If the answer for a different A and N results in a negative, the MOD function should make the answer positive by adding 7 to the number to make it fall between 0 and 7.

MOD in Facer does not appear to do that.

Therefore, I have to test if the MOD result is negative and then add 7.

Either way, I need to add a conditional on whether MOD is giving a negative answer and if so, add 7 in this case to correct the result…before doing more math.

But going back to this MOD question, has any experienced a negative answer with MOD and how did you deal with it?

3 Likes