Jump to content

Loop structures: Difference between revisions

Line 202:
===while===
 
while(true) {
{
foo();
}
 
===do while===
 
do {
foo();
} while(test);
===for===
 
for(var i = 0; i < 5; i++) {
{
foo();
}
 
===foreachfor in===
 
//iterate through propertiesproperty names of an object as if through a collection
var obj = {prop1:"a", prop2:"b", prop3:"c"};
for (var key in obj)
alert( key + ' is set to ' + obj[key] );
 
=== for each in===
 
//iterate through property values of an object
var obj = {prop1:"a", prop2:"b", prop3:"c"};
for each(var element in obj)
alert( element );
 
==[[Pascal]]==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.