Jaa


Break Statements

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

X++ provides a break statement for the following:

  • Terminating loops

  • Separation of case statements in a switch statement

Syntax

break;

Loops

When used within a while, do...while, or for loop, the loop is terminated and execution continues from the statement following the loop as shown in the following example.

    mainMenu = SysDictMenu::newMainMenu();
    enum = mainMenu.getEnumerator();
    found = false;
     
    while (enum.moveNext())
    {
        menuItem = enum.current();
        if (menuItem.label() == parentDictsecuritykey.label())
        {
            found = true;
            break;
        }
    }
    if (found) //Belongs in Navigation Pane.
    {
        ...
    }

Switch

When break is used within a switch statement, the execution of the case branch terminates, and the statement following the switch is executed as shown in the following example.

switch (Debtor.AccountNo)

{

case "1000": 

do_something;

break;

case "2000":

do_something_else;

break;

default:

default_statement; 

break;

}

If the Debtor account number is 1000, the program executes do_something, and then continues execution after the switch statement.

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.