{"id":62,"date":"2020-01-09T11:18:42","date_gmt":"2020-01-09T11:18:42","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/javascript\/?p=62"},"modified":"2020-08-06T06:02:33","modified_gmt":"2020-08-06T06:02:33","slug":"loop-control","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/","title":{"rendered":"JavaScript &#8211; Loop Control"},"content":{"rendered":"<p>In <a href=\"https:\/\/www.kindsonthegenius.com\/javascript\/07-javascript-switch-statement\/\">Tutorial 7<\/a>, we learnt about Loops( For, For..in, While and Do&#8230;While).<br \/>\nIn this tutorial, we would learn about Loop control statements.<\/p>\n<p>These are statements you can use to alter\u00a0 the normal flow of control in the loop. For example, you may have to terminate a loop before it&#8217;s complete execution. Another situation may be that you may need to skip part of the loop based on certain criteria. In situations like this, JavaScript provides the break and continue statements.The break statement helps you come out of a loop prior to its normal completion while the continue statement helps you jump tot he next iteration of the loop.<\/p>\n<p>Let&#8217;s now discuss these statements in more details<\/p>\n<ol>\n<li><a href=\"#t1\">The break Statement<\/a><\/li>\n<li><a href=\"#t2\">The continue Statement<\/a><\/li>\n<li><a href=\"#t3\">Using Labels<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t1\">1. The break Statement<\/strong><\/h5>\n<p>You us the break statement when you want the loop to terminate before its execution completes. So when the program encounters a break statement, it jumps out of the body of the loop to the statements following the loop. Remember this is the same break statement used with <a href=\"https:\/\/www.kindsonthegenius.com\/javascript\/07-javascript-switch-statement\/\">switch statements in Tutorial 7<\/a>.<\/p>\n<p>The flowchart for the break statement is shown below<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_64\" aria-describedby=\"caption-attachment-64\" style=\"width: 464px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2020\/01\/Loop-Control-Statements.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-64 \" src=\"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2020\/01\/Loop-Control-Statements.jpg\" alt=\"Loop Control Statements\" width=\"464\" height=\"332\" srcset=\"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2020\/01\/Loop-Control-Statements.jpg 699w, https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2020\/01\/Loop-Control-Statements-300x215.jpg 300w\" sizes=\"auto, (max-width: 464px) 100vw, 464px\" \/><\/a><figcaption id=\"caption-attachment-64\" class=\"wp-caption-text\">Loop Control Statements<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>Let&#8217;s take an example.<\/p>\n<p>The code below shows a loop looping from 1 to 10. But a break statement is encountered when the value of x reaches 5.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;html&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;head&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;title&gt;<\/span>Break Statement Demo<span style=\"color: #007700;\">&lt;\/title&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;\/head&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;body&gt;<\/span>      \r\n      <span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type =<\/span> <span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span><span style=\"color: #007700;\">&gt;<\/span>\r\n         <span style=\"color: #888888;\">&lt;!--<\/span>\r\n         <span style=\"color: #008800; font-weight: bold;\">var<\/span> x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>;\r\n         <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Begining of Loop&lt;br \/&gt; \"<\/span>);\r\n         \r\n         <span style=\"color: #008800; font-weight: bold;\">while<\/span> (x <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>) {\r\n            <span style=\"color: #008800; font-weight: bold;\">if<\/span> (x <span style=\"color: #333333;\">==<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>) {\r\n               <span style=\"color: #008800; font-weight: bold;\">break<\/span>;   <span style=\"color: #888888;\">\/\/ breaks out of the loop<\/span>\r\n            }\r\n            x <span style=\"color: #333333;\">=<\/span> x <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>;\r\n            <span style=\"color: #007020;\">document<\/span>.write( x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>);\r\n         }         \r\n         <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"End of the loop!&lt;br \/&gt; \"<\/span>);\r\n         <span style=\"color: #888888;\">\/\/--&gt;<\/span>\r\n      <span style=\"color: #007700;\">&lt;\/script&gt;<\/span>     \r\n      <span style=\"color: #007700;\">&lt;p&gt;<\/span>Try using different value for x...<span style=\"color: #007700;\">&lt;\/p&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;\/body&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/html&gt;<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t2\">2. The continue Statement<\/strong><\/h5>\n<p>The continue statement is used to tell the JavaScript interpreter to move to the next iteration of the loop. This means skipping the remaining part of the current iteration.<\/p>\n<p>As an example, the code below encounters a continue statement at x = 5, the it skips the writing of the value of x and jumps to 6. So, if you run this code you will notice that 5 would not be written.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;html&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;head&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;title&gt;<\/span>Continue Statement Demo<span style=\"color: #007700;\">&lt;\/title&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;\/head&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;body&gt;<\/span>      \r\n      <span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type =<\/span> <span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span><span style=\"color: #007700;\">&gt;<\/span>\r\n         <span style=\"color: #888888;\">&lt;!--<\/span>\r\n            <span style=\"color: #008800; font-weight: bold;\">var<\/span> x <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>;\r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Entering the loop&lt;br \/&gt; \"<\/span>);\r\n         \r\n            <span style=\"color: #008800; font-weight: bold;\">while<\/span> (x <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>) {\r\n               x <span style=\"color: #333333;\">=<\/span> x <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>;\r\n               \r\n               <span style=\"color: #008800; font-weight: bold;\">if<\/span> (x <span style=\"color: #333333;\">==<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>) {\r\n                  <span style=\"color: #008800; font-weight: bold;\">continue<\/span>;   <span style=\"color: #888888;\">\/\/ skip rest of the loop<\/span>\r\n               }\r\n               <span style=\"color: #007020;\">document<\/span>.write( x <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>);\r\n            }         \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Exiting the loop!&lt;br \/&gt; \"<\/span>);\r\n         <span style=\"color: #888888;\">\/\/--&gt;<\/span>\r\n      <span style=\"color: #007700;\">&lt;\/script&gt;<\/span>    \r\n      <span style=\"color: #007700;\">&lt;p&gt;<\/span>Try using different value for x...<span style=\"color: #007700;\">&lt;\/p&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;\/body&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/html&gt;<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t3\">3. Loop Control Using Labels<\/strong><\/h5>\n<p>Labels can be used to indicate the particular loop that is being handled. This is because there can be more than one loop in a program. For example, we can have nested loops: inner and outer loop.<\/p>\n<p>To add a label, simple specify the label name followed by a colon (:), before the loop begins.<\/p>\n<p>Note: Line breaks cannot be placed between a label and its corresponding break or continue statement. The next example shows how to use a label with nested loops.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;html&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;head&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;title&gt;<\/span>Labels Demo<span style=\"color: #007700;\">&lt;\/title&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;\/head&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;body&gt;<\/span>      \r\n      <span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type =<\/span> <span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span><span style=\"color: #007700;\">&gt;<\/span>\r\n         <span style=\"color: #888888;\">&lt;!--<\/span>\r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"start of the loop!&lt;br \/&gt; \"<\/span>);\r\n            outerloop<span style=\"color: #333333;\">:<\/span>        <span style=\"color: #888888;\">\/\/ This is the labe         <\/span>\r\n            <span style=\"color: #008800; font-weight: bold;\">for<\/span> (<span style=\"color: #008800; font-weight: bold;\">var<\/span> i <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>; i <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>; i<span style=\"color: #333333;\">++<\/span>) {\r\n               <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Outer loop: \"<\/span> <span style=\"color: #333333;\">+<\/span> i <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>);\r\n               innerloop<span style=\"color: #333333;\">:<\/span>\r\n               <span style=\"color: #008800; font-weight: bold;\">for<\/span> (<span style=\"color: #008800; font-weight: bold;\">var<\/span> j <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>; j <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>; j<span style=\"color: #333333;\">++<\/span>) {\r\n                  <span style=\"color: #008800; font-weight: bold;\">if<\/span> (j <span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span> ) <span style=\"color: #008800; font-weight: bold;\">break<\/span> ;           <span style=\"color: #888888;\">\/\/ Terminate the inner loop<\/span>\r\n                  <span style=\"color: #008800; font-weight: bold;\">if<\/span> (i <span style=\"color: #333333;\">==<\/span> <span style=\"color: #0000dd; font-weight: bold;\">2<\/span>) <span style=\"color: #008800; font-weight: bold;\">break<\/span> innerloop;  <span style=\"color: #888888;\">\/\/ Same effect as above<\/span>\r\n                  <span style=\"color: #008800; font-weight: bold;\">if<\/span> (i <span style=\"color: #333333;\">==<\/span> <span style=\"color: #0000dd; font-weight: bold;\">4<\/span>) <span style=\"color: #008800; font-weight: bold;\">break<\/span> outerloop;  <span style=\"color: #888888;\">\/\/ Terminate the outer loop<\/span>\r\n                  <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Inner loop: \"<\/span> <span style=\"color: #333333;\">+<\/span> j <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\" &lt;br \/&gt;\"<\/span>);\r\n               }\r\n            }        \r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"End of loops!&lt;br \/&gt; \"<\/span>);\r\n         <span style=\"color: #888888;\">\/\/--&gt;<\/span>\r\n      <span style=\"color: #007700;\">&lt;\/script&gt;<\/span>  \r\n      <span style=\"color: #007700;\">&lt;p&gt;<\/span>Try changing the values of i and j...<span style=\"color: #007700;\">&lt;\/p&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;\/body&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/html&gt;<\/span>\r\n<\/pre>\n<p>Here&#8217;s another example. This example uses a continue statement to jump to the outer loop<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007700;\">&lt;html&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;head&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;title&gt;<\/span>Labels Demo<span style=\"color: #007700;\">&lt;\/title&gt;<\/span>\r\n    <span style=\"color: #007700;\">&lt;\/head&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;body&gt;<\/span>      \r\n      <span style=\"color: #007700;\">&lt;script <\/span><span style=\"color: #0000cc;\">type =<\/span> <span style=\"background-color: #fff0f0;\">\"text\/javascript\"<\/span><span style=\"color: #007700;\">&gt;<\/span>\r\n         <span style=\"color: #888888;\">&lt;!--<\/span>\r\n         <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"start of the loop!&lt;br \/&gt; \"<\/span>);\r\n         outerloop<span style=\"color: #333333;\">:<\/span>     <span style=\"color: #888888;\">\/\/ This is the label        <\/span>\r\n         <span style=\"color: #008800; font-weight: bold;\">for<\/span> (<span style=\"color: #008800; font-weight: bold;\">var<\/span> i <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>; i <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>; i<span style=\"color: #333333;\">++<\/span>) {\r\n            <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Outerloop: \"<\/span> <span style=\"color: #333333;\">+<\/span> i <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>);\r\n            <span style=\"color: #008800; font-weight: bold;\">for<\/span> (<span style=\"color: #008800; font-weight: bold;\">var<\/span> j <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>; j <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>; j<span style=\"color: #333333;\">++<\/span>) {\r\n               <span style=\"color: #008800; font-weight: bold;\">if<\/span> (j <span style=\"color: #333333;\">==<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>) {\r\n                  <span style=\"color: #008800; font-weight: bold;\">continue<\/span> outerloop;\r\n               }\r\n               <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"Innerloop: \"<\/span> <span style=\"color: #333333;\">+<\/span> j <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\"&lt;br \/&gt;\"<\/span>);\r\n            }\r\n         }              \r\n         <span style=\"color: #007020;\">document<\/span>.write(<span style=\"background-color: #fff0f0;\">\"End of loops!&lt;br \/&gt; \"<\/span>);\r\n         <span style=\"color: #888888;\">\/\/--&gt;<\/span>\r\n      <span style=\"color: #007700;\">&lt;\/script&gt;<\/span>  \r\n      <span style=\"color: #007700;\">&lt;p&gt;<\/span>Try changing the values of i and j...<span style=\"color: #007700;\">&lt;\/p&gt;<\/span>\r\n   <span style=\"color: #007700;\">&lt;\/body&gt;<\/span>\r\n<span style=\"color: #007700;\">&lt;\/html&gt;<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>I recommend you try to run all the code snippet. Also remember to watch the video for clarification.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Tutorial 7, we learnt about Loops( For, For..in, While and Do&#8230;While). In this tutorial, we would learn about Loop control statements. These are statements &hellip; <\/p>\n","protected":false},"author":395,"featured_media":63,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[9,10,11],"class_list":["post-62","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript-tutorials","tag-break-statement","tag-continue-statement","tag-labels"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JavaScript - Loop Control - JavaScript Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript - Loop Control - JavaScript Tutorial\" \/>\n<meta property=\"og:description\" content=\"In Tutorial 7, we learnt about Loops( For, For..in, While and Do&#8230;While). In this tutorial, we would learn about Loop control statements. These are statements &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/\" \/>\n<meta property=\"og:site_name\" content=\"JavaScript Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-09T11:18:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-06T06:02:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2020\/01\/Loop-Control.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"857\" \/>\n\t<meta property=\"og:image:height\" content=\"388\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"headline\":\"JavaScript &#8211; Loop Control\",\"datePublished\":\"2020-01-09T11:18:42+00:00\",\"dateModified\":\"2020-08-06T06:02:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/\"},\"wordCount\":431,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/wp-content\\\/uploads\\\/sites\\\/6\\\/2020\\\/01\\\/Loop-Control.jpg\",\"keywords\":[\"break statement\",\"continue statement\",\"labels\"],\"articleSection\":[\"JavaScript Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/\",\"name\":\"JavaScript - Loop Control - JavaScript Tutorial\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/wp-content\\\/uploads\\\/sites\\\/6\\\/2020\\\/01\\\/Loop-Control.jpg\",\"datePublished\":\"2020-01-09T11:18:42+00:00\",\"dateModified\":\"2020-08-06T06:02:33+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/wp-content\\\/uploads\\\/sites\\\/6\\\/2020\\\/01\\\/Loop-Control.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/wp-content\\\/uploads\\\/sites\\\/6\\\/2020\\\/01\\\/Loop-Control.jpg\",\"width\":857,\"height\":388},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/loop-control\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript &#8211; Loop Control\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/\",\"name\":\"JavaScript Tutorial\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/javascript\\\/author\\\/kindsonthegenius-2\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript - Loop Control - JavaScript Tutorial","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:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript - Loop Control - JavaScript Tutorial","og_description":"In Tutorial 7, we learnt about Loops( For, For..in, While and Do&#8230;While). In this tutorial, we would learn about Loop control statements. These are statements &hellip;","og_url":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/","og_site_name":"JavaScript Tutorial","article_published_time":"2020-01-09T11:18:42+00:00","article_modified_time":"2020-08-06T06:02:33+00:00","og_image":[{"width":857,"height":388,"url":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2020\/01\/Loop-Control.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"headline":"JavaScript &#8211; Loop Control","datePublished":"2020-01-09T11:18:42+00:00","dateModified":"2020-08-06T06:02:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/"},"wordCount":431,"commentCount":0,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2020\/01\/Loop-Control.jpg","keywords":["break statement","continue statement","labels"],"articleSection":["JavaScript Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/","url":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/","name":"JavaScript - Loop Control - JavaScript Tutorial","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2020\/01\/Loop-Control.jpg","datePublished":"2020-01-09T11:18:42+00:00","dateModified":"2020-08-06T06:02:33+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2020\/01\/Loop-Control.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-content\/uploads\/sites\/6\/2020\/01\/Loop-Control.jpg","width":857,"height":388},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/loop-control\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/javascript\/"},{"@type":"ListItem","position":2,"name":"JavaScript &#8211; Loop Control"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/#website","url":"https:\/\/www.kindsonthegenius.com\/javascript\/","name":"JavaScript Tutorial","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/javascript\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/javascript\/author\/kindsonthegenius-2\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/posts\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/users\/395"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/comments?post=62"}],"version-history":[{"count":3,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"predecessor-version":[{"id":112,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/posts\/62\/revisions\/112"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/media\/63"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/javascript\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}