Do

From Game Editor

Jump to: navigation, search

A do loop ( or do while loop ) is a block of code which executes until a conditional expression evaluates to false. Unlike a while loop, a do loop executes the code block first and then evaluates the conditional.

Example:

int x = -1;
do
{
  --x;
}
while ( x > 0 );

The value of x after the loop would be -2. This is because x is decremented once before evaluating the condition expression x > 0 at the bottom of the loop.

Flow control can be modified by break and continue statements.

Example:

int x = 1;
do
{
  if ( x % 2 == 0 )
  {
    continue;
  } 
  printf( "%d is odd", x );
}
while ( ++x < 100 );

This example would print all the odd numbered integers from 1 to 99.

Retrieved from "http://game-editor.com/Do"