Loops


while

pre-tested loop
the condition expression is evaluated before executing the body of the loop

while (i < total) { 
   i++
}

do while

post-tested loop (executed at least once)
the condition expression is evaluated after executing the body of the loop

do { 
   i++
} while (i < total)

for

for ( i = 0; i < total; i++) { 
}

for in

Added in ES 2009.
This traverses all enumerable properties of an object
Iterates over the property keys of an object
This cannot iterate through a collection

var myobject = { 
   name: "Steve"
   age: 20
};
for (var propertyVal in myobject) {
   write(propertyVal);
   write(myobject[propertyVal]);
}

var people = ["steve","john","people"]; 
for (i in people) {
   alert(people[i]);
}



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext