Bungee Logic : Iteration Basics

Page Status: Beta
Jump to: navigation, search

Back to Bungee Logic

Contents

[edit] Iteration Basics

All Bungee Iteration constructs (for, while, and collection) share certain behaviors that are important to understand to avoid subtle bugs.

[edit] Intrinsic Variables

Each iteration construct has a set of Intrinsic Variables that are provided for programming convenience and to give control over the loop. These Intrinsic Variables must not be deleted or renamed, and should only be modified as documented. Incorrectly modifying the iteration Intrinsic Variables will result in undefined behavior.

[edit] Variable Initialization

Variables declared in an iteration are only initialized once, not each time through the loop. For example, the following loop is intended to create 5 new objects, but instead only creates one:

for (CurrentIndex = 0; CurrentIndex < 5; CurrentIndex++)
{
  var int CurrentIndex;
  var boolean StopIterating;
  var Object newobject = new Object;
}

To correctly create 5 new objects, the object creation must be done in a separate assignment statement as follows:

for (CurrentIndex = 0; CurrentIndex < 5; CurrentIndex++)
{
  var int CurrentIndex;
  var boolean StopIterating;
  var Object newobject;

  newobject = new Object;
}

[edit] See Also

Collection Iteration
For Iteration
While Iteration

    Copyright © 2005 - 2008 Bungee Labs. All rights reserved.