{"id":61,"date":"2026-03-01T15:46:39","date_gmt":"2026-03-01T10:46:39","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=61"},"modified":"2026-03-13T10:05:35","modified_gmt":"2026-03-13T05:05:35","slug":"break-and-continue","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/break-and-continue\/","title":{"rendered":"Break and Continue"},"content":{"rendered":"\n<p>he <strong>break<\/strong> and <strong>continue<\/strong> statements are used to control the flow of loops in Python.<br>They help you stop a loop early or skip certain iterations.<\/p>\n\n\n\n<p>These statements can be used inside both <strong>for loops<\/strong> and <strong>while loops<\/strong>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>BREAK STATEMENT<\/strong><\/h1>\n\n\n\n<p>The <strong>break<\/strong> statement immediately stops the loop.<br>When break is executed, the loop ends and control moves to the next line after the loop.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Syntax<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">break<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example with For Loop<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in range(1, 6):<br>    if i == 4:<br>        break<br>    print(i)<\/pre>\n\n\n\n<p>Output:<br>1<br>2<br>3<\/p>\n\n\n\n<p>The loop stops when <code>i<\/code> becomes 4.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example with While Loop<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">num = 1while num &lt;= 5:<br>    if num == 3:<br>        break<br>    print(num)<br>    num += 1<\/pre>\n\n\n\n<p>The loop ends when <code>num<\/code> reaches 3.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>CONTINUE STATEMENT<\/strong><\/h1>\n\n\n\n<p>The <strong>continue<\/strong> statement skips the current iteration and moves to the next one.<br>It does not stop the loop completely.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Syntax<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">continue<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example with For Loop<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in range(1, 6):<br>    if i == 3:<br>        continue<br>    print(i)<\/pre>\n\n\n\n<p>Output:<br>1<br>2<br>4<br>5<\/p>\n\n\n\n<p>The number 3 is skipped.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example with While Loop<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">num = 0while num &lt; 5:<br>    num += 1<br>    if num == 2:<br>        continue<br>    print(num)<\/pre>\n\n\n\n<p>The number 2 is skipped.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>DIFFERENCE BETWEEN BREAK AND CONTINUE<\/strong><\/h1>\n\n\n\n<p>Break \u2192 Stops the loop completely<br>Continue \u2192 Skips one iteration and continues the loop<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>WHEN TO USE BREAK<\/strong><\/h1>\n\n\n\n<p>\u2022 When a required condition is met<br>\u2022 When searching for something in a loop<br>\u2022 When you want to exit early<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>WHEN TO USE CONTINUE<\/strong><\/h1>\n\n\n\n<p>\u2022 When you want to skip specific values<br>\u2022 When filtering data inside a loop<br>\u2022 When ignoring unwanted conditions<\/p>\n\n\n\n<p>Understanding <strong>break and continue<\/strong> gives you better control over loop execution and helps in writing efficient Python programs.<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773377485714\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/python\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">PYTHON FUNDAMENTALS (PYF) > Control Flow > Break and Continue<\/span><\/span><\/div>\n\n\n<p><\/p>\n","protected":false},"menu_order":20,"template":"","class_list":["post-61","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Break and Continue - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Learn Python break and continue statements to control loops, stop execution early, skip iterations, and manage loop flow efficiently.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/python\/lesson\/break-and-continue\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Break and Continue - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Learn Python break and continue statements to control loops, stop execution early, skip iterations, and manage loop flow efficiently.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/break-and-continue\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-13T05:05:35+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/break-and-continue\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/break-and-continue\\\/\",\"name\":\"Break and Continue - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-03-01T10:46:39+00:00\",\"dateModified\":\"2026-03-13T05:05:35+00:00\",\"description\":\"Learn Python break and continue statements to control loops, stop execution early, skip iterations, and manage loop flow efficiently.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/break-and-continue\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/break-and-continue\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/break-and-continue\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PYTHON FUNDAMENTALS (PYF) > Control Flow > Break and Continue\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\",\"name\":\"One Language. Endless Possibilities\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Break and Continue - One Language. Endless Possibilities","description":"Learn Python break and continue statements to control loops, stop execution early, skip iterations, and manage loop flow efficiently.","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:\/\/gigz.pk\/python\/lesson\/break-and-continue\/","og_locale":"en_US","og_type":"article","og_title":"Break and Continue - One Language. Endless Possibilities","og_description":"Learn Python break and continue statements to control loops, stop execution early, skip iterations, and manage loop flow efficiently.","og_url":"https:\/\/gigz.pk\/python\/lesson\/break-and-continue\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-13T05:05:35+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/python\/lesson\/break-and-continue\/","url":"https:\/\/gigz.pk\/python\/lesson\/break-and-continue\/","name":"Break and Continue - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-03-01T10:46:39+00:00","dateModified":"2026-03-13T05:05:35+00:00","description":"Learn Python break and continue statements to control loops, stop execution early, skip iterations, and manage loop flow efficiently.","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/break-and-continue\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/break-and-continue\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/break-and-continue\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"PYTHON FUNDAMENTALS (PYF) > Control Flow > Break and Continue"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/python\/#website","url":"https:\/\/gigz.pk\/python\/","name":"One Language. Endless Possibilities","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson\/61","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/media?parent=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}