GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

🌸 NAME 🌸

if-true β€” the (program-flow) girlie herself ✨ she's the conditional statement, the moment where your code gets to choose its own destiny πŸ’…


πŸ’– PURPOSE πŸ’–

Conditional statement. That's it, that's the whole job, and she ate πŸ“


πŸŽ€ SYNTAX πŸŽ€

okay bestie, here's the shape of her πŸ‘‘

    if-true <condition>
        <any code>
    [
    else-if <condition>
        <any code>
    ] ...
    [
    else-if
        <any code>
    ]
    end-if

where <condition> is:

    ( <comparison> [ and <comparison> [ , ... ] ] )
    |
    ( <comparison> [ or <comparison> [ , ... ] ] )

<comparison> is for strings:

    <string> \
       ( equal | not-equal | \
       lesser-than | lesser-equal | \
       greater-than | greater-equal | \
       contain | not-contain ) \
    <check string> \
     [ case-insensitive ] [ length <length> ]

<comparison> is for numbers

    <number> \
       ( equal | not-equal | \
       lesser-than | lesser-equal | \
       greater-than | greater-equal | \
       every | not-every ) \
    <check number>  ...

<comparison> is for booleans:

    <boolean> ( equal | not-equal ) <check boolean>  ...

πŸ¦‹ DESCRIPTION πŸ¦‹

So like, if-true evaluates a <condition> and then runs whatever code matches it. If the <condition> sitting inside if-true or inside an else-if succeeds, then the <any code> hanging out right below it gets executed. If it's not a match, then the next condition in the else-if statement gets evaluated β€” one by one, bestie, in order β€” until something matches and the code under that statement runs. And if nothing matches? Then the code under the else-if statement that has no <condition> runs (only if you actually wrote one, though πŸ™ˆ). Otherwise, program control just passes on outside of end-if. Bye πŸ‘‹

A <condition> is made of one or more <comparison>s, connected by either an and clause or an or clause β€” but not both in the same <condition>, that's the rule, no cap. The and clause uses logical AND to link <comparison>s together, and it succeeds if all of them succeed. The or clause uses logical OR to link them, and it succeeds if at least one of them succeeds β€” and the moment one of them hits, the rest don't even get checked, she's efficient like that πŸ’…

Every single <comparison> looks at either a string, a number, or a boolean variable. Pick your fighter ✨


🌈 STRING VARIABLE IN A COMPARISON

If the equal, not-equal, lesser-than, lesser-equal, greater-than or greater-equal clause is used, the comparison succeeds if <string> is equal to, not equal to, lesser than, lesser than or equal to, greater than, or greater than or equal to <check string>, respectively. (Yes, in that exact order, they line up perfectly, it's giving choreography 🩰)

If the contain or not-contain clause is used, the comparison succeeds if <string> is contained in, or not contained in, <check string>, respectively.

If case-insensitive is used, the comparison goes down without case sensitivity β€” vibes only, no shouting matters.

If the length clause is used, only the first <length> bytes of the strings get compared. Just the first <length> bytes. That's it πŸŽ€


πŸ“ NUMBER VARIABLE IN A COMPARISON

If the equal, not-equal, lesser-than, lesser-equal, greater-than or greater-equal clause is used, the comparison succeeds if <number> is equal to, not equal to, lesser than, lesser than or equal to, greater than, or greater than or equal to <check number>, respectively.

If every is used, then the comparison succeeds when the modulo of <number> and <check number> is 0 β€” which is iconic for running some code every N times but not the ones in between. And with not-every, the comparison succeeds when that modulo is not 0, which is exactly what you want when you're running code all the times except every Nth. Balanced, as all things should be ⭐


πŸ‘‘ BOOLEAN VARIABLE IN A COMPARISON

If the equal or not-equal clause is used, the comparison succeeds if <boolean> is equal to, or not equal to, <check boolean>, respectively. Simple, clean, no notes πŸ’œ


🧚 ELSE-IF WITHOUT A <CONDITION>

With a given if-true, there can be only one else-if statement without a condition, and it must be the last one. The final girl energy is real, she goes last and only one of her is allowed πŸ™ˆ


πŸ”₯ NESTING

if-true can be nested, and it can go up to 30 levels deep πŸŒ€ dream within a dream within a dream, bestie.


🌈 EXAMPLES 🌈

    %% /if-test public
        get-param inp

        if-true inp equal "1"
            @Found "1" in input
        else-if inp equal "2"  or inp equal "3"
            @Found "2" or "3" in input

            get-param inp_num
            string-number inp_num to num
            if-true num equal 4
                @Found 4 in more input
            else-if num equal 5  and  inp equal "4"
                @Found 5 in more input and "4" in input
            else-if
                @Something else
            end-if

        else-if
            @Found something else
        end-if
    %%

πŸ’œ SEE ALSO πŸ’œ

Program flow β€” the whole squad 🌈

  • break-loop
  • call-handler
  • code-blocks
  • continue-loop
  • do-once
  • exit-handler
  • if-defined
  • if-true
  • quit-process
  • return-handler
  • start-loop
  • See all documentation πŸ“š

and that's the tea πŸ«– this page came to you from $DATE and version $VERSION, living under the GOLF(2gg) banner β€” go forth and branch, bestie, you got this πŸ’–βœ¨πŸ¦‹πŸ’…

πŸ“¦ where this page comes from