Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A loop is a control statement that allows us to repeat a code block. Loops contain a conditional which determines how many times the code block is repeated.

...

The for in loop loops through the properties of an object.


for([variable declaration], [condition], [increment step]) {

...

Code Block
languagejs
let person = {name:"Maik", surname:"Muster"};
let x;

for (x in person) {
      print(x)
 }

While-loop

The while loop cycles through a block of code as long as its specified condition is true.


while ([condition]) {

 [code block]
}

...

Code Block
languagejs
linenumberstrue
let x=0;
while(x <= 100)
{
   print(x);
   x++;
}

Do-While-loop

The do/while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, it will then repeat the loop as long as the condition is true.


do{
} while([condition]);


Code Block
languagejs
linenumberstrue
let x=0;

do
{
   print(x);
   x++;
} while(x <= 100);

...