JavaScript LoopsThe JavaScript loops are used to iterate the piece of code using for, while, do while or for-in loops. It makes the code compact. It is mostly used in array. There are four types of loops in JavaScript.
1) JavaScript For loopThe JavaScript for loop iterates the elements for the fixed number of times. It should be used if number of iteration is known. The syntax of for loop is given below. Let’s see the simple example of for loop in javascript. Test it NowOutput: 2) JavaScript while loopThe JavaScript while loop iterates the elements for the infinite number of times. It should be used if number of iteration is not known. The syntax of while loop is given below. Let’s see the simple example of while loop in javascript. Test it NowOutput: 3) JavaScript do while loopThe JavaScript do while loop iterates the elements for the infinite number of times like while loop. But, code is executed at least once whether condition is true or false. The syntax of do while loop is given below. Let’s see the simple example of do while loop in javascript. Test it NowOutput: 4) JavaScript for in loopThe JavaScript for in loop is used to iterate the properties of an object. We will discuss about it later.
Next TopicJavascript Function
|
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week