Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Newbie question about "if" and "else"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Newbie question about "if" and "else"

    Hi,
    I am slowly getting into the basics of the NT editor.

    I am able now to create rules and follow the format for inserting/adding/editing of variables.

    I am trying to figure out how to optimize a little bit the codes that I am creating ...as I reckon that though they are functional, might not be the best way in terms of performance and load.


    This is why I want to ask on an advice of how the optimum code would be for the following:

    if(Time[0].Month == 1)
    {
    Variable5 = 1;
    }

    else if(Time[0].Month == 2)
    {
    Variable5 = 0;
    }

    Should I make it with "else" within the first {} and get rid of the whole "else if" new condition?

    Thanks

    #2
    Originally posted by nikolaalx View Post
    Hi,
    I am slowly getting into the basics of the NT editor.

    I am able now to create rules and follow the format for inserting/adding/editing of variables.

    I am trying to figure out how to optimize a little bit the codes that I am creating ...as I reckon that though they are functional, might not be the best way in terms of performance and load.


    This is why I want to ask on an advice of how the optimum code would be for the following:

    if(Time[0].Month == 1)
    {
    Variable5 = 1;
    }

    else if(Time[0].Month == 2)
    {
    Variable5 = 0;
    }

    Should I make it with "else" within the first {} and get rid of the whole "else if" new condition?

    Thanks
    You cannot have an else statement directly in an if block. What you have written is the correct way to write it.

    Comment


      #3
      nikolaalx, you could even remove the braces in single line assignments and simplify a bit to -

      Code:
      if (Time[0].Month == 1)
      	Variable5 = 1;
      
      else if(Time[0].Month == 2)
      	Variable5 = 0;

      Comment


        #4
        If I could add something, if there are only two options in the conditional, say it matters only if the months are even or odd, you don't need the 'else if', just an 'else':

        Code:
        if ( [I]... month is an even number ... [/I])
        
            Variable5 = 1;
        
        else Variable5 = 0; // There's only one other option: the month number is odd
        Also, at the end of a list, when you've exhausted all the options (say you've come to December), then you only need an 'else' on its own.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        553 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        100 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        543 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        546 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X