Statements: do-while loop
The do-while loop iteration statement lets you repeat a nested statement.
Syntax
dostatementwhile(condition)
Discussion
The do-while loop statement executes the nested statement repeatedly as long as the condition evaluates to the boolean value true. Unlike the while statement, the condition is evaluated at end of every iteration, resulting in the nested statement being executed at least once. To execute multiple statements within the loop, you can group those together within a block statement. For example:
array int32 values[ 16 ]; var int32 inx = 0; var int32 sum = 0; [ ... ] // Sum the array values until the value 1000 has been exceeded or // there is no more array values to add. do { sum = sum + values[ inx ]; inx = inx + 1; } while (( sum <= 1000 ) && ( inx < values.size ));
The do-while statement can be combined with the statements break and continue. break causes the loop to exit immediately passing the control to the next statement following do-while. In this case, the condition is not evaluated. When continue statement is executed inside a loop, the control jumps to the beginning of the loop for next iteration, skipping over all following statements inside the body of loop for the current iteration. For example:
do { var int32 v = Array[ inx ]; if ( v > 10 ) continue; if ( !v ) break; sum += math_pow( 2, v ); } while ( inx++ < count );