do…while statements

The do...while block is similar to the while block in that it evaluates an expression and uses the Boolean result to determine the next course of action. The principal difference is that Gosu tests the expression for validity after executing the statement block, instead of prior to executing the statement block. The statements in the statement block execute at least once when execution first accesses the block.

  • If the expression is initially true, Gosu executes the statements in the statement block repeatedly until the expression becomes false. At this point, Gosu exits the do...while block and continues statement execution at the next statement after the do...while statement.
  • If the expression is initially false, Gosu executes the statements in the statement block once, then evaluates the condition. If nothing in the statement block has changed so that the expression still evaluates to false, Gosu continues statement execution at the next statement after the do...while block. If action in the statement block causes the expression to evaluate to true, Gosu executes the statement block repeatedly until the expression becomes false, as in the previous case.

Syntax

do {
  <statements>
} while (<expression>)

Example

// Print the digits
var i = 0

do {
  print(i)
  i = i + 1
} while (i < 10)