LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Nested If Statement

    Employee
    Posted 07-25-2013 22:10

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Borg_species5618

    Hello All,

    Can lava storm perform multiple nested If statements ?
    Normally in other script languages we close nested If statements with 'End If' or something like it am I missing something here

    At present I have to create two seperate Filter Nodes where I would like to create one, here is what I wouold like to do.
    ---------------------------------------------------------------------------------------
    if (regexIsMatch ('Source', "KNRBILL") or regexIsMatch ('Source', "KNRCASH")) then
    IsBillingActive = "Y"
    if Check > 0 then
    PValue = 0 - (left('YValue',Check)).double()
    else
    PValue = 'Value'
    else
    IsBillingActive = "N"
    ---------------------------------------------------------------------------------------


    Thankyou

    Frank


  • 2.  RE: Nested If Statement

    Employee
    Posted 07-26-2013 01:07

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Theo

    As a "personal" best practise I tend to use brackets for the if statements. Brackets, combined with indentation spaces give you a really good overview of the commands and allow you to both expand/collapse and have a better visualization in the "Script" view of the node.




    Nested If Statement.brg


  • 3.  RE: Nested If Statement

    Employee
    Posted 07-26-2013 07:12

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    The language can handle nested IFs with ease.
    The problem in your example above is that you have two statements for the first THEN clause.
    You essentially have this:
    if condition then
    z=1
    w=1
    else
    x=1

    To support multiple statements in the predicate THEN clause, you must use brackets.
    if condition then {
    z=1
    w=1
    }
    else
    x=1


  • 4.  RE: Nested If Statement

    Employee
    Posted 07-29-2013 09:53

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ltolleson

    This is how I would format the statement that you have supplied. I also added PValue = "Some Default Value" to the else in case the first condition is false. This will ensure the PValue is always populated.

    if (regexIsMatch ('Source', "KNRBILL") or regexIsMatch ('Source', "KNRCASH")) then
    {
    IsBillingActive = "Y"
    if Check > 0 then
    {
    PValue = 0 - (left('YValue',Check)).double()
    }
    else
    {
    PValue = 'Value'
    }
    }
    else
    {
    IsBillingActive = "N"
    PValue = "Some Default Value"
    }


    Note the use of brackets {}. Brackets are only required when there are multiple statements to be processed after an IF or ELSE, but I find it best practice to always use them.
    Here is what the code would look like with minimal use of brackets {}. The nested IF THEN ELSE in this case would not require brackets {}.

    if (regexIsMatch ('Source', "KNRBILL") or regexIsMatch ('Source', "KNRCASH")) then
    {
    IsBillingActive = "Y"
    if Check > 0 then
    PValue = 0 - (left('YValue',Check)).double()
    else
    PValue = 'Value'
    }
    else
    {
    IsBillingActive = "N"
    PValue = "Some Default Value"
    }