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 | ||
---|---|---|
| ||
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 | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
let x=0; do { print(x); x++; } while(x <= 100); |
...