if statement

The if statement is a fundamental control structure in Tipcontrol and similar to languages such as C++. It allows you to execute certain blocks of code conditionally, based on the evaluation of an expression.

Structure of an if Statement:

Components:

  1. Condition: An expression evaluated to determine whether it is true (non-zero) or false (zero).
  2. Code Block: The block of code that executes if the condition evaluates to true. This block is enclosed within curly braces {}.

Optional else Clause

You can extend the if statement with an else clause to specify code to execute when the condition is false:

Simple Example

    number = 10;

    // Check if the number is positive, negative, or zero

    if (number > 0) {

        lib.log(“The number is positive.”);

    } else if (number < 0) {

        lib.log(“The number is negative.”);

    } else {

        lib.log(“The number is zero.”);

    };

Explanation:

  • Conditionnumber > 0 checks if number is greater than zero.
  • Nested checkselse if provides additional conditional checks when the previous if condition is false.
  • else Clause: Executes if none of the preceding conditions are true.