Loop
When we want to repeat the same code over different values, we generally use a programming constructs loop.
What are types of loop?
-
Entry Control Loop(condition checked in the starting of loop e.g. for, while)
-
Exit Control Loop( condition check at end of loop e.g. do while) JavaScript support 3 basic loops construct for syntax of for loop:-
-
for Loop
for (initialization; condition; increment / decrement) {// code block to be executed} -
while Loop
Initialization;while (condition) {// code block to be executedincrement / decrement;} -
do...while Loop
initialization;do() {// code block to be executedincrement/decrement;}while(condition) -
for of [es6 introduce]
for (element of arrayName) {// code block}// E.g.const array = [1, 2, 3, 4, 5, 6, 7];for (const element of array) console.log(element);// output 1 2 3 4 5 6 7