• Tutorials

  • Home
  • GPDL $WHILE Keyword

    DungeonCraft Help Home

    The $WHILE keyword is used to repeat a group of instructions while a condition is true.

      $WHILE ( expression ) { statements } ; 

    The expression is evaluated and if it does not equal the empty string then the statements are executed. Then the expression is evaluated again, and so on until the expression does equal the empty string, which represents 'false'. Example:

      y = 0;
      x = 3;
      $WHILE ( $NOT ( $nEQUAL ( x, 0)))
      {
        y = $nPLUS ( y, x);
        x = $nMinus ( x, 1);
      }; 

    This example computes the sum of the integers from 1 to 3. When x equals zero, the loops exits and y will be equal to "6".

    Notice that the body of the loop must be contained in braces even if it consists of only one statement.