

{"id":51757,"date":"2019-03-14T11:46:00","date_gmt":"2019-03-14T06:16:00","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=51757"},"modified":"2019-08-13T18:51:15","modified_gmt":"2019-08-13T13:21:15","slug":"loop-in-javascript","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/","title":{"rendered":"JavaScript Loops &#8211; Learn to Implement Various Types of Loop Statements"},"content":{"rendered":"<p>Have you ever been punished in school and asked to write the sentence <em>\u201cI will not be late for the class again.\u201d<\/em> fifty times? It\u2019s so boring, right? Well, JavaScript saves us from this trouble. When we ask JavaScript to execute the same task repeatedly, it\u2019s a lot more efficient than us. How so? Simple, <em>JavaScript uses loops<\/em>! This tutorial is all about what JavaScript loops are and how we can use them. In this article, we will learn about different types of loops available in JavaScript. These include <em>for, while and do&#8230;while loops<\/em>. There are also some loops that are special in JavaScript, like<strong> for&#8230;in and for&#8230;of<\/strong> loops. Let\u2019s learn about all the loops with their syntax and examples.<\/p>\n<p><strong><em>But before we start our tutorial I recommend you to have a brief look at <a href=\"https:\/\/data-flair.training\/blogs\/javascript-conditional-statements\/\">JavaScript Conditional Statements<\/a><\/em><\/strong><\/p>\n<h2>What is a JavaScript Loop?<\/h2>\n<p>JavaScript Loop provides a quick and easy way to do repetitive tasks. They offer to perform iterations with only a few lines of code. Iteration is the number of times you want to repeat the task <em>(that number can even be zero)<\/em>. Be sure you understand all of them, so you can implement the best loop statement for a given situation.<\/p>\n<p>There are primarily two types of loops in any programming language, and JavaScript is no exception. These are:<\/p>\n<ul>\n<li><strong>Entry Controlled Loops<\/strong>: Any loop where we check the test condition before entering the loop is an entry controlled loop. In these loops, the test condition determines whether the program will enter the loop or not. These include<strong> for, while, etc.<\/strong><\/li>\n<li><strong>Exit Controlled Loops<\/strong>: Any loop where we check the test condition after the statements are executed once is an exit controlled loop. In these loops, the test condition determines whether or not the program will exit the loop. This category includes <strong>do&#8230;while<\/strong> loop.<\/li>\n<\/ul>\n<p>We repeat the sequence of instructions until the test condition is true. JavaScript provides the following loop statements to achieve this:<\/p>\n<ul>\n<li>while statement<\/li>\n<li>for statement<\/li>\n<li>do..while statement<\/li>\n<li>for&#8230;in statement<\/li>\n<li>for&#8230;of statement<\/li>\n<li>labeled statement<\/li>\n<li>break statement<\/li>\n<li>continue statement<\/li>\n<\/ul>\n<p>We will study the labeled, break and continue statement in our next tutorial on JavaScript Loop Control.<\/p>\n<p>Let&#8217;s understand JavaScript Loop with the help of an example, my first job is to print <em>\u201cDataFlair Tutorial for JavaScript\u201d<\/em> 5 times for the posters that I want to create. Instead of typing them 5 times, I\u2019m going to use loops to lighten my workload. The first loop statement I can use is a <strong>while<\/strong> statement.<\/p>\n<p><em>(I\u2019ve added the \u201cLoop end\u201d statement just so I know when my loop ended.)<\/em><\/p>\n<h3>1. while Statement<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-Statement.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-67080 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-Statement.png\" alt=\"while Statement - JavaScript Loops\" width=\"600\" height=\"349\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-Statement.png 600w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-Statement-150x87.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-Statement-300x175.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-Statement-520x302.png 520w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>A <strong>while<\/strong> statement in JavaScript executes until our boolean condition evaluates to <strong>true<\/strong>. This loop is an entry controlled loop.<\/p>\n<ul>\n<li>If the test condition returns<strong> false<\/strong>, then control passes to the statement just after the loop.<\/li>\n<li>If the test condition returns<strong> true<\/strong>, the loop body is executed and the condition is tested again.<\/li>\n<\/ul>\n<p>The syntax for a <strong>while<\/strong> statement is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">while ( boolean condition)\r\n  statement<\/pre>\n<p>For multiple statements, group them with a block statement ({&#8230;}).<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n\r\n    &lt;script&gt;\r\n      var iterator1 = 0; \/\/iteration variable initialized with 0\r\n      while (iterator1 &lt; 5) \/\/testing the condition\r\n      {\r\n        document.write(iterator1 + 1 + \". \" + \"DataFlair Tutorial for JavaScript&lt;\/br&gt;\");\r\n        iterator1++; \/\/incrementing the value of the variable\r\n\r\n      }\r\n      document.write(\"&lt;\/br&gt;Loop end\");\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63842\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while.jpg\" alt=\"JavaScript while\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-63844 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-op.jpg\" alt=\"javascript while op\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/while-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>This loop statement is helpful when you don\u2019t always know the number of iterations you need. It provides you with the facility to execute your code as long as the condition holds true.<\/p>\n<h3>2. for Statement<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-Statement.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-67085 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-Statement.png\" alt=\"for Statement - JavaScript Loops\" width=\"840\" height=\"384\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-Statement.png 840w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-Statement-150x69.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-Statement-300x137.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-Statement-768x351.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-Statement-520x238.png 520w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/a><br \/>\nJavaScript <strong>for<\/strong> <strong>loops<\/strong> are similar to Java and C language\u00a0<strong>for<\/strong> <strong>loops<\/strong>. It\u2019s an entry controlled loop. It consists of three parts, separated with a semicolon:<\/p>\n<ul>\n<li><strong>Initialization:<\/strong> It initializes the loop with an iteration variable and executes once at the beginning of the loop.<\/li>\n<li><strong>Condition:<\/strong> It specifies a certain condition in the loop that determines whether the loop body will execute or not. If the condition returns true, the code inside the <strong>for<\/strong> loop will execute. If it returns false, the control moves onto the statement after the loop.<\/li>\n<li><strong>Increment\/ Decrement:<\/strong> This section increments or decrements the value of our iteration variable by 1.<\/li>\n<\/ul>\n<p>These three sections are not compulsory, but make sure you remember the semicolons. The syntax of <strong>for<\/strong> <strong>statement<\/strong> looks like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for ([initialization]; [condition]; [increment\/decrement]) {\r\n\/\/loop body\r\n}<\/pre>\n<p>This loop is useful when you know how many times you want the loop to execute. This loop also reduces the total lines in your code to achieve the same task.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n\r\n    &lt;script&gt;\r\n      for (var iterator1 = 0; iterator1 &lt; 5; iterator1++) \/\/initialization, condition, increment\r\n      {\r\n        document.write(iterator1 + 1 + \". \" + \"DataFlair Tutorial for JavaScript&lt;\/br&gt;\");\r\n      }\r\n      document.write(\"&lt;\/br&gt;Loop end\");\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63846\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.jpg\" alt=\"javascript for\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-63847 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-op.jpg\" alt=\"javascript for op\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h3>3. do..while Statement<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do..while-Statement.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-67086 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do..while-Statement.png\" alt=\"do..while Statement - JavaScript Loops\" width=\"610\" height=\"364\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do..while-Statement.png 610w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do..while-Statement-150x90.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do..while-Statement-300x179.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do..while-Statement-520x310.png 520w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>This is an exit controlled loop; the loop body executes at least once, even if the condition is not true. This is because the condition is tested when the loop body ends. If the condition returns <strong>true<\/strong>, the code inside the loop executes again. If it returns <strong>false<\/strong>, the JavaScript interpreter exits the loop.<\/p>\n<p>The syntax of a <strong>do&#8230;while<\/strong> statement is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">do\r\n{\r\n  \/\/code executed at least once\r\n}while (condition);<\/pre>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n\r\n    &lt;script&gt;\r\n      var iterator1 = 0; \/\/iteration variable initialized with 0\r\n      do \/\/enter loop\r\n      {\r\n        document.write(iterator1 + 1 + \". \" + \"DataFlair Tutorial for JavaScript&lt;\/br&gt;\");\r\n        iterator1++; \/\/incrementing the value of the variable\r\n\r\n      }while (iterator1 &lt; 5); \/\/testing the condition\r\n      document.write(\"&lt;\/br&gt;Loop end\");\r\n    &lt;\/script&gt;\r\n\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while_.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63848\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while_.jpg\" alt=\"javascript do.while\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while_.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while_-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while_-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while_-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while_-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while_-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-63849 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while-op.jpg\" alt=\"javascript do.while op\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/do.while-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h3>4. for&#8230;in Statement<\/h3>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for...in-Statement.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-67087 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for...in-Statement.png\" alt=\"for...in Statement - JavaScript Loops\" width=\"577\" height=\"566\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for...in-Statement.png 577w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for...in-Statement-150x147.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for...in-Statement-300x294.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for...in-Statement-520x510.png 520w\" sizes=\"auto, (max-width: 577px) 100vw, 577px\" \/><\/a><\/p>\n<p>This is a modified <strong>for<\/strong> <strong>loop<\/strong> that doesn\u2019t require the programmer to know the number of iterations the loop needs to perform. It creates a loop iterating over all the enumerable properties of an object. The<strong> keys<\/strong> store the key of the current property and we access the property\u2019s value with it. This means that the loop executes a specific set of statements for each distinct property in a<em><strong> <a href=\"https:\/\/data-flair.training\/blogs\/javascript-objects\/\">JavaScript Object<\/a>.<\/strong> <\/em>The working of a <strong>for&#8230;in<\/strong> statement in <a href=\"https:\/\/developer.mozilla.org\/bm\/docs\/Web\/JavaScript\">JavaScript<\/a> is similar to<strong> for-each<\/strong> loop in Java.<\/p>\n<p>The syntax of a <strong>for&#8230;in<\/strong> statement in JavaScript looks like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for (keys in objProperties)\r\n{\r\n  statements\r\n}<\/pre>\n<p>The reason why the developers created the <strong>for&#8230;in loop<\/strong> is to work with user-defined properties in an object. It is better to use a traditional <strong>for<\/strong> <strong>loop<\/strong>\u00a0over Array elements with numeric indexes. But, for this example, we are using a numeric array so you can understand how the loop works.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n    &lt;script&gt;\r\n      var courses = [\"JavaScript\", \"IOT\", \"Python\", \"R\", \"Data Mining\", \"AI\"];\r\n  \/\/declaring array with some elements\r\n      document.write(\"&lt;b&gt;Some of the courses provided by DataFlair are listed below.&lt;\/b&gt;&lt;\/br&gt;\");\r\n      for(course in courses) \/\/loop to print every course in courses\r\n      {\r\n        document.write(courses[course] + \" Tutorials&lt;\/br&gt;\"); \/\/accessing course values with numeric keys\r\n      }\r\n    &lt;\/script&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in_.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63850\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in_.jpg\" alt=\"javascript for.in\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in_.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in_-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in_-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in_-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in_-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in_-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-63851 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in-op.jpg\" alt=\"javascript for.in op\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.in-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h3>5. for&#8230;of Statement<\/h3>\n<p>In the last JavaScript statement, we had to access the array\u2019s values with the help of square brackets [ ]. We couldn\u2019t access them directly and it makes your program more error-prone. So the JavaScript developers got us a new way to access these values directly. This makes our code a lot more efficient than before because the values store the property\u2019s value, not the key.<\/p>\n<p>A <strong>for&#8230;of statement<\/strong> looks as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for (values of objProperties)\r\n{\r\n  statements\r\n}<\/pre>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n  &lt;body&gt;\r\n    &lt;script&gt;\r\n      var courses = [\"JavaScript\", \"IOT\", \"Python\", \"R\", \"Data Mining\", \"AI\"]; \r\n  \/\/declaring array with some elements\r\n      document.write(\"&lt;b&gt;Some of the courses provided by DataFlair are listed below.&lt;\/b&gt;&lt;\/br&gt;\");\r\n      for(course of courses) \/\/loop to print every course in courses\r\n      {\r\n        document.write(course + \" Tutorials&lt;\/br&gt;\"); \/\/accessing course values directly\r\n      }\r\n    &lt;\/script&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><strong>Screenshot:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of_.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-63852\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of_.jpg\" alt=\"javascript for.of\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of_.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of_-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of_-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of_-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of_-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of_-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of-op.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-63853 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of-op.jpg\" alt=\"javascript for.of op\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of-op.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of-op-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of-op-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of-op-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of-op-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/for.of-op-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>Did you check the DataFlair&#8217;s guide on <a href=\"https:\/\/data-flair.training\/blogs\/javascript-array\/\">JavaScript Array<\/a><\/strong><\/em><\/p>\n<h3>6. Infinite Loop<\/h3>\n<p>One of the most common mistakes programmers make while using loops is creating an infinite loop. This happens when we accidentally add a condition that always returns true. It is very important that you avoid them in your code, but I still want you to practice these loops. Try thinking of some situations where the condition is always true. Let me give you an example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">while(1){\r\n  \/\/statements\r\n}<\/pre>\n<h3>Difference between for and while loop in JavaScript<\/h3>\n<p>Though the for and while loops work the same, there are some key differences you need to remember while deciding which one to use.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Difference-between-for-and-while-loop.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-67129\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Difference-between-for-and-while-loop.jpg\" alt=\"Difference between for and while loop in JavaScript\" width=\"2734\" height=\"2742\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Difference-between-for-and-while-loop.jpg 2734w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Difference-between-for-and-while-loop-150x150.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Difference-between-for-and-while-loop-300x300.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Difference-between-for-and-while-loop-768x770.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Difference-between-for-and-while-loop-1021x1024.jpg 1021w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Difference-between-for-and-while-loop-160x160.jpg 160w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Difference-between-for-and-while-loop-320x320.jpg 320w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/08\/Difference-between-for-and-while-loop-520x522.jpg 520w\" sizes=\"auto, (max-width: 2734px) 100vw, 2734px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>Here we come to the end of our tutorial on JavaScript Loops. In this article, we took a brief look at the different loop statements available in JavaScript like <strong>while<\/strong>, <strong>do&#8230;while, for,<\/strong> etc. We discussed infinite loops and compared <strong>for and while loops<\/strong>. In the end, I would personally suggest you practice these loops as much as you can to master them.<\/p>\n<p><em><strong>Time to check out the next tutorial on <a href=\"https:\/\/data-flair.training\/blogs\/javascript-loop-control\/\">JavaScript Loop Control<\/a>\u00a0<\/strong><\/em><\/p>\n<p>Express your views regarding the\u00a0JavaScript Loops article in the comment section below. We will be glad to hear from you.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1460,&quot;href&quot;:&quot;https:\\\/\\\/developer.mozilla.org\\\/bm\\\/docs\\\/Web\\\/JavaScript&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20201130000822\\\/https:\\\/\\\/developer.mozilla.org\\\/bm\\\/docs\\\/Web\\\/JavaScript&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 07:35:26&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2025-12-14 12:48:38&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2025-12-19 16:01:18&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-02 05:32:30&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-05 19:50:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-09 07:53:29&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-12 17:53:07&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-15 18:05:42&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-19 04:19:31&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-22 15:51:58&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-26 16:36:18&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-01-30 05:54:36&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-02 17:35:29&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-06 14:42:18&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-11 11:19:51&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-14 12:03:01&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-18 16:15:46&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-22 14:15:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-27 08:10:27&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-03 09:04:41&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-08 14:29:22&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-12 11:33:39&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-17 04:22:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-20 15:25:16&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-24 12:07:52&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-29 08:48:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-08 16:30:39&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-22 02:42:26&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-27 10:57:04&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-01 17:54:16&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-05 08:23:41&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-11 09:47:19&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-14 19:09:02&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-18 05:55:16&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-23 01:38:30&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-26 05:15:49&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-05-29 09:07:38&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-04 05:11:44&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-07 15:48:27&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-11 01:56:04&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-11 01:56:04&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever been punished in school and asked to write the sentence \u201cI will not be late for the class again.\u201d fifty times? It\u2019s so boring, right? Well, JavaScript saves us from this&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":67088,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18979],"tags":[20816,20817,20596],"class_list":["post-51757","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-for-and-while-loop-difference","tag-javascript-loop-statements","tag-javascript-loops"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JavaScript Loops - Learn to Implement Various Types of Loop Statements - DataFlair<\/title>\n<meta name=\"description\" content=\"Understand JavaScript Loops &amp; types of loop statements with the help of diagram, syntax &amp; implementation examples &amp; difference between for &amp; while loops in JavaScript.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Loops - Learn to Implement Various Types of Loop Statements - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Understand JavaScript Loops &amp; types of loop statements with the help of diagram, syntax &amp; implementation examples &amp; difference between for &amp; while loops in JavaScript.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-14T06:16:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-08-13T13:21:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Loops.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript Loops - Learn to Implement Various Types of Loop Statements - DataFlair","description":"Understand JavaScript Loops & types of loop statements with the help of diagram, syntax & implementation examples & difference between for & while loops in JavaScript.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Loops - Learn to Implement Various Types of Loop Statements - DataFlair","og_description":"Understand JavaScript Loops & types of loop statements with the help of diagram, syntax & implementation examples & difference between for & while loops in JavaScript.","og_url":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2019-03-14T06:16:00+00:00","article_modified_time":"2019-08-13T13:21:15+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Loops.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"JavaScript Loops &#8211; Learn to Implement Various Types of Loop Statements","datePublished":"2019-03-14T06:16:00+00:00","dateModified":"2019-08-13T13:21:15+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/"},"wordCount":1237,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Loops.jpg","keywords":["for and while loop difference","JavaScript Loop Statements","JavaScript Loops"],"articleSection":["JavaScript Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/loop-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/","url":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/","name":"JavaScript Loops - Learn to Implement Various Types of Loop Statements - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Loops.jpg","datePublished":"2019-03-14T06:16:00+00:00","dateModified":"2019-08-13T13:21:15+00:00","description":"Understand JavaScript Loops & types of loop statements with the help of diagram, syntax & implementation examples & difference between for & while loops in JavaScript.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/loop-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Loops.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/07\/JavaScript-Loops.jpg","width":802,"height":420,"caption":"JavaScript Loops Tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/loop-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"JavaScript Tutorial","item":"https:\/\/data-flair.training\/blogs\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Loops &#8211; Learn to Implement Various Types of Loop Statements"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/51757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=51757"}],"version-history":[{"count":8,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/51757\/revisions"}],"predecessor-version":[{"id":67811,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/51757\/revisions\/67811"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/67088"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=51757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=51757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=51757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}