Microsoft Dynamics AX 2012 R3 Development-2 Locus IT Services

Microsoft Dynamics AX 2012 R3 Development-2

Locus IT ServicesMicrosoft Dynamics AX 2012 R3 Development-2

Lesson 4- Loops

Loops

Repetitive statements, also known as loops, conditionally control data input and output.

There are three main loops in X++:

  • While
  • Do while
  • For statement

It can be combined with the following statements:

  • Break statement:X++ provides a break statement for the following:
    • Terminating
    • Separation of case statements in a switch statement
  • Continue statements:

    The continue statement causes the system to move straight to the next iteration of a for, while, or do…while. For do or while, the test is executed immediately. In a for statement, the increment step is executed.If you use continue with an if statement, you can avoid deeply nested if…else statements.

The for loop is very similar to the while loop, but has the following additions:

  • The initial value to a control variable can be assigned.
  • There is a statement for incrementing or decrementing the variable.

These additions make it especially useful for traversing lists, containers, and arrays because they have a fixed number of elements. You can also apply a statement to each element and increment your way through the elements, setting the condition to test for the last element.

Loop statements: for, while, and do…while

There are three loop statements: forwhile, and dowhile. It repeats its statement until the condition that is set for the loop is false. Within the loop statements, you can use break and continue statements.

For loops : It repeatedly executes one or more statements for as long as the conditional expression is true. The statement is executed as many times as the condition is met. The body might be executed zero or more times, depending on the results of the condition test. A for loop differs from other loops because an initial value can be assigned to a control variable, and because there is a statement for incrementing or decrementing the variable. These additions make a for loop especially useful for traversing lists, containers, and arrays, because they have a fixed number of elements. You can also apply a statement to each element and increment your way through the elements, setting the condition to test for the last element.

Locus IT Project Management Office
What’s it?