{"id":85,"date":"2026-05-20T11:12:42","date_gmt":"2026-05-20T11:12:42","guid":{"rendered":"https:\/\/gigz.pk\/cpp\/?post_type=lesson&#038;p=85"},"modified":"2026-05-22T07:59:44","modified_gmt":"2026-05-22T07:59:44","slug":"break-and-continue","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/cpp\/?lesson=break-and-continue","title":{"rendered":"break and continue"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>break<\/code> and <code>continue<\/code> statements in C++ are loop control statements used to change the normal flow of loops. They help manage program execution more efficiently.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is break Statement?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>break<\/code> statement is used to immediately terminate a loop or switch statement.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When <code>break<\/code> is executed:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The loop stops instantly<\/li>\n\n\n\n<li>Control moves to the next statement after the loop<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax of break<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>break;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Example of break Statement<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br>    for (int i = 1; i &lt;= 10; i++) {<br><br>        if (i == 5) {<br>            break;<br>        }<br><br>        cout &lt;&lt; i &lt;&lt; endl;<br>    }<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>1<br>2<br>3<br>4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop stops when <code>i<\/code> becomes 5.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is continue Statement?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>continue<\/code> statement skips the current iteration and moves to the next iteration of the loop.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When <code>continue<\/code> is executed:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Remaining code inside the loop is skipped<\/li>\n\n\n\n<li>The next loop iteration begins immediately<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax of continue<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>continue;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Example of continue Statement<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br>    for (int i = 1; i &lt;= 5; i++) {<br><br>        if (i == 3) {<br>            continue;<br>        }<br><br>        cout &lt;&lt; i &lt;&lt; endl;<br>    }<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>1<br>2<br>4<br>5<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The number 3 is skipped.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Difference Between break and continue<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>break<\/th><th>continue<\/th><\/tr><\/thead><tbody><tr><td>Stops the loop completely<\/td><td>Skips only current iteration<\/td><\/tr><tr><td>Exits loop immediately<\/td><td>Continues with next iteration<\/td><\/tr><tr><td>Used to terminate loops<\/td><td>Used to skip specific conditions<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Example Using while Loop<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br>    int i = 0;<br><br>    while (i &lt; 5) {<br>        i++;<br><br>        if (i == 2) {<br>            continue;<br>        }<br><br>        if (i == 4) {<br>            break;<br>        }<br><br>        cout &lt;&lt; i &lt;&lt; endl;<br>    }<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Why break and continue are Important<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These statements are important because they:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Improve loop control<\/li>\n\n\n\n<li>Make code cleaner and more efficient<\/li>\n\n\n\n<li>Help avoid unnecessary iterations<\/li>\n\n\n\n<li>Simplify conditional logic<\/li>\n\n\n\n<li>Are widely used in real-world programs<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Real-Life Example<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">break Example<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a fire alarm:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Once the alarm rings, everyone immediately exits the building<\/li>\n\n\n\n<li>The process stops instantly<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">continue Example<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Think of skipping absent students during attendance:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Attendance continues<\/li>\n\n\n\n<li>Only one student is skipped<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>break<\/code> and <code>continue<\/code> statements in C++ are powerful loop control tools. <code>break<\/code> stops the loop completely, while <code>continue<\/code> skips the current iteration and continues execution. Both help make programs more efficient and easier to manage.<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1779436847105\"><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\/cpp\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">C++ Fundamentals (Beginner Level) > Loops > break and continue<\/span><\/span><\/div>","protected":false},"menu_order":19,"template":"","class_list":["post-85","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>break and continue - Learn C++Language with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn C++ break and continue statements with examples to control loop flow, skip iterations, and exit loops 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\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"break and continue - Learn C++Language with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn C++ break and continue statements with examples to control loop flow, skip iterations, and exit loops efficiently.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn C++Language with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-22T07:59:44+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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/?lesson=break-and-continue\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"break and continue - Learn C++Language with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/#website\"},\"datePublished\":\"2026-05-20T11:12:42+00:00\",\"dateModified\":\"2026-05-22T07:59:44+00:00\",\"description\":\"Learn C++ break and continue statements with examples to control loop flow, skip iterations, and exit loops efficiently.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/cpp\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Fundamentals (Beginner Level) > Loops > break and continue\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/\",\"name\":\"Learn C++Language with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/?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 - Learn C++Language with GiGz.PK","description":"Learn C++ break and continue statements with examples to control loop flow, skip iterations, and exit loops 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\/","og_locale":"en_US","og_type":"article","og_title":"break and continue - Learn C++Language with GiGz.PK","og_description":"Learn C++ break and continue statements with examples to control loop flow, skip iterations, and exit loops efficiently.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Learn C++Language with GiGz.PK","article_modified_time":"2026-05-22T07:59:44+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/cpp\/?lesson=break-and-continue","url":"https:\/\/gigz.pk\/","name":"break and continue - Learn C++Language with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/cpp\/#website"},"datePublished":"2026-05-20T11:12:42+00:00","dateModified":"2026-05-22T07:59:44+00:00","description":"Learn C++ break and continue statements with examples to control loop flow, skip iterations, and exit loops efficiently.","breadcrumb":{"@id":"https:\/\/gigz.pk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/cpp"},{"@type":"ListItem","position":2,"name":"C++ Fundamentals (Beginner Level) > Loops > break and continue"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/cpp\/#website","url":"https:\/\/gigz.pk\/cpp\/","name":"Learn C++Language with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/cpp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/lesson\/85","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=85"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}