{"id":920,"date":"2022-07-11T19:40:35","date_gmt":"2022-07-11T19:40:35","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=920"},"modified":"2023-04-25T20:25:31","modified_gmt":"2023-04-25T20:25:31","slug":"break-keyword-javascript","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/break-keyword-javascript\/","title":{"rendered":"Break Keyword Javascript"},"content":{"rendered":"<p style=\"text-align: center;\"><strong>Break Keyword Javascript<\/strong><\/p>\n<p>The break keyword is a very interesting concept and a very useful keyword. As the name says, it is used to break, out of the loop.<\/p>\n<p>You might have used this break keyword in the switch statement as well. The break keyword <a href=\"https:\/\/www.youtube.com\/playlist?list=PLSvOEh55hdXVt5Jht4mjDJNTAuHKfPMAT\">Javascript<\/a> was being used there, so as to get out after the relevant case executes. Here, you can understand the break keyword, with some logic like this \u2013 when the break keyword is encountered in the loop, we just move out of the loop. That&#8217;s it. This is like, the loop is running, and the break executes, and we are out of the loop.<\/p>\n<h2 style=\"text-align: center;\">Break Keyword Javascript<\/h2>\n<p><iframe loading=\"lazy\" title=\"Javascript Break and Continue | Lecture 31 | JavaScript for Beginners\" width=\"696\" height=\"392\" src=\"https:\/\/www.youtube.com\/embed\/Kyn33NsssLc?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>So, as stated earlier, we are going to have a look at the break keyword <a href=\"https:\/\/gyanipandit.com\/programming\/javascript\/\">Javascript<\/a>, which basically is used to break out of the loop. Do not worry if you have not got the concept properly. As we have a look at the example, you would get the idea behind it.<\/p>\n<p>Now, let&#8217;s have a look at the below example, which is used to demonstrate the use of the break keyword. &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-921 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/break-and-continue-keywords.jpg\" alt=\"\" width=\"478\" height=\"179\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/break-and-continue-keywords.jpg 478w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/break-and-continue-keywords-300x112.jpg 300w\" sizes=\"auto, (max-width: 478px) 100vw, 478px\" \/><br \/>\nIn the above example, for some reason, we are breaking out of the loop, when the value of i is 5(i do not know why we are even doing this, but yeah, we understand the break keyword this way). So, in the above program, the loop runs with peace of mind, and then, when the value of i becomes 5, the condition becomes true, the break keyword executes, and we are out of the loop. Have a look at the output &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-922 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/break-and-continue-keywords-1.jpg\" alt=\"\" width=\"681\" height=\"162\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/break-and-continue-keywords-1.jpg 681w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/04\/break-and-continue-keywords-1-300x71.jpg 300w\" sizes=\"auto, (max-width: 681px) 100vw, 681px\" \/><br \/>\nAs you can see, the break statement was executed, and as soon as this happened, we are out of the loop. This break keyword is pretty interesting and useful, and you can use the break keyword as and when required. You can also practice the programs, which involve the break keyword somehow, to get familiar with the break keyword.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Break Keyword Javascript The break keyword is a very interesting concept and a very useful keyword. As the name says, it is used to break, out of the loop. You might have used this break keyword in the switch statement as well. The break keyword Javascript was being used there, so as to get out [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[14,15],"class_list":{"0":"post-920","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-javascript-tutorial","7":"tag-javascript","8":"tag-javascript-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=920"}],"version-history":[{"count":4,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/920\/revisions"}],"predecessor-version":[{"id":6083,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/920\/revisions\/6083"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}