| Applying science to business management |
  
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.
|