Vanguard Software
Forecasting & Planning Solutions
Home Products Solutions Services Customers Partners Company
 
Applying science to business management

contents.gifindex.gifprev1.gifnext1.gif

for/in

The for/in statement is used to execute a loop iteration for each property in an object. You might remember that an object is like a list except that each element is given a name instead of an index number. For/in allows you to dynamically extract those property names. This statement has the format

for( variable in object )
  
statement

The following code will display the name and value of each property in the object named box.

var box={length:3,width:4,height:2};
for(var name in box)
print(name+" = "+box[name]+"\n");
flush;

Executing this code will cause DScript to display the following text:

height = 2
length = 3
width = 4

Note that the object properties are not extracted in the same order as they were defined. DScript stores properties inside an object in alphabetical order. So, a for/in statement will always extract properties in alphabetical order as well.

  Demand Planning  |  Financial Forecasting
Forecasting Software  |  Strategic Planning Software  |  Decision Tree Software
Decision Support Software  |  Expert System Software  |  Online Surveys

Contact Us  |  Terms of Use  |  Privacy Policy  |  Site Map
Vanguard Software
© 2011 Vanguard Software Corporation
Print this page   Email this page to a friend