Jaa


Do...while Loops

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

The do...while loop is similar to the while loop, but differs in that the condition follows the statement. The statement is always performed at least once. The do...while loop is well suited for tasks that always must be done at least once, for example, to get parameters for a report.

Syntax

do

{ statement }

while

( expression ) ;

statement can be a block of statements.

Example

Following is an example of a do...while loop designed to find the smallest power of 10 that is larger than _Value.

    int FindPower(real _Value)
    {
        int ex=-1;
        real curVal;
        ;
       
        do
       {
          ex += 1;
          curVal = power(10, ex);
       }
       
       while (_Value>curVal);
     
       return ex;
    } 

See also

Loops

Conditional Statements

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