if else statement in X++ Programing Language

Rumman Ansari   Software Engineer   2023-10-25   7618 Share
☰ Table of Contents

Table of Content:


Learn how to use the "if-else" statement in X++ programming language to add conditional logic to your code. Understand the syntax and usage of if-else statements in X++ to control the flow of your program based on specific conditions.

Syntax


if(condition_check ){
  // Statements
}
else{
  // statements
}

In this code snippet, an "if-else" statement is used for conditional execution of code based on a condition check. Here's a brief explanation:

  1. The condition_check is a condition or expression that is evaluated. If the condition_check evaluates to true, the code block inside the corresponding curly braces {} following the "if" statement is executed.

  2. Inside the " if" block, you can place any statements or actions that should be executed when the condition_check is true.

  3. If the condition_check evaluates to false, meaning it does not meet the specified condition, the program will skip the code block inside the " if" statement and instead execute the statements within the curly braces following the " else" keyword.

  4. The " else" statement provides an alternative set of statements to be executed when the condition_check is false. These statements can be any code that should be executed when the condition_check is not met.

In summary, the "if-else" statement allows for decision-making based on a condition. If the condition_check is true, the statements inside the " if" block are executed; otherwise, the statements inside the " else" block are executed.


if else Example


 
// if else decision making example x++

static void Examples(Args _args)
{
   int a = 13;
   int b = 12;
   if( a == b)
   {
    info("a and b is same/equal");
   }
    else{
    info("a and b is not same/equal");
    }

}


The above code is an example of decision-making using the "if-else" statement in X++ programming language. Here's a short explanation:

  1. Two integer variables, a and b, are declared and assigned values. In this case, a is assigned the value 13 and b is assigned the value 12.

  2. The "if" statement is used to check if a is equal to b by using the == comparison operator. If the condition evaluates to true, the code block inside the curly braces immediately following the "if" statement is executed.

  3. Inside the "if" block, the info() function is called to display a message "a and b are same/equal" using the Info log functionality.

  4. If the condition in the "if" statement evaluates to false, the code block inside the curly braces following the "else" keyword is executed.

  5. Inside the "else" block, the info() function is called to display a message "a and b are not same/equal" using the Info log functionality.

In summary, this code checks if the values of variables a and b are equal. If they are equal, it displays a message indicating they are the same. Otherwise, it displays a message indicating they are not the same.