while statements

Gosu evaluates the while() expression, which must evaluate to true or false, and uses the Boolean result to determine the next course of action:

  • 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 while statement and continues statement execution at the next statement after the while statement.
  • If the expression is initially false, Gosu does not execute any of the statements in the statement block, and continues statement execution at the next statement after the while statement.

Syntax

while (expression) {
  statements
}

If the while() expression tests whether an iterator has more items available, the statements in the statement block can process the items that the iterator provides. The Iterator.next method returns an item of type Object. You must downcast that item to the expected type before processing it. Because downcasting could fail at run time if the actual type is not compatible with the expected type, you must consider the risks of that technique. In the following example, the object retrieved from the iterator.next method is cast to the type of object required, which is Payment in this case.

var iterator = this.getPaymentsIterator(true)
while (iterator.hasNext()) {
  var payment = (iterator.next() as Payment)
  // Your code here
}