LAFlO.
($?apples?SingularPluralI have .
This is as simple as ternary expressions get:
apples = 1 ? "apple" : "apples"
Unpacked (if-then-else):
if apples = 1 then return "apple";
otherwise return "apples".
Each operand would require its own block (either "Expression true" or "Set variable"), so this is an easy way to save three blocks in your flow (five if you include the ternary used to set the dialog title).?appleapplesBackExit@?**?Value ComparisonYour number is , which is 5.
Simple, but the logic takes five blocks, which is just silly. This is a perfect place to use a nested ternary expression:
myNumber < 5 ? "less than" : myNumber > 5 ? "greater than" : "equal to"
This one follows the if-else if-else pattern:
if myNumber < 5 then return "less than";
else if myNumber > 5 then return "greater than";
otherwise return "5"
The ternary can be embedded directly in the text of this dialog, and you just saved five blocks.myNumberC@ less thanC@greater thanequal toBackExit@"?C" $$ 0. <?
Last Day: month?year@@y@Y@<@=w@w@w@ w@$@>@?Last day of :
Here is the ternary (again, January is 0):
month = 1 ? (year % 4 != 0 || (year % 400 != 0 && year % 100 = 0) ? 28 : 29) : month = 3 || month = 5 || month = 8 || month = 10 ? 30 : 31
This one is pretty simple except for the first bit. If month = 1, there is a nested ternary that checks for leap year (same as earlier, just incorporated into this expression) and returns 28 or 29, as appropriate. Next it checks for the months with 30 days (3, 5, 8, or 10); otherwise it returns 31.JanuaryFebruaryMarchAprilMayJuneJulyAugust SeptemberOctoberNovemberDecemberww?@@y@Y@<@=w@w@w@ w@$@>@?BackExit?Dates are SimpleYear:
The year a leap year.
Determined using this ternary:
year % 4 != 0 || (year % 400 != 0 && year % 100 = 0) ? "is not" : "is"
Which is a simple ternary with a more complex logic check (the 'if' operator in the 'if-then-else' statement):
if "year % 4 != 0 || (year % 400 != 0 && year % 100 = 0)" returns true then the ternary returns "is not";
otherwise it returns "is"
Month:
This could be determined with a ternary expression, but an ad-hoc array makes for a simpler and clearer statement. Note that January is 0, February is 1, and so on.@@y@Yis notisJanuaryFebruaryMarchAprilMayJuneJulyAugust SeptemberOctoberNovemberDecemberwMoreExit@*w@p?choice??How Complex?BasicLevel 2More Complicated??IntroTernary expressions are just if-then-else statements combined into one compact and confusing package. They follow this format:
? :
Which just means
if then else
So if evaluates to true, then the ternary returns , otherwise it returns . At its simplest it's not too bad. But and can be literals or expressions; and any of the three operands can themselves be ternary expressions. It's easy to see how things can get out of hand.ExamplesExitTernary Expressions;9 igk7m