{"id":9476,"date":"2021-06-03T17:44:23","date_gmt":"2021-06-03T12:14:23","guid":{"rendered":"https:\/\/pynative.com\/?p=9476"},"modified":"2021-06-06T09:27:57","modified_gmt":"2021-06-06T03:57:57","slug":"python-break-continue-pass","status":"publish","type":"post","link":"https:\/\/pynative.com\/python-break-continue-pass\/","title":{"rendered":"Python Break, Continue, and Pass"},"content":{"rendered":"\n<p>In this article, you will learn how to use \u200ethe <code>break<\/code>, <code>continue<\/code> and <code>pass<\/code> statements when <a href=\"https:\/\/pynative.com\/python-for-loop\/\">working with loops in Python<\/a>. We use break, continue statements to alter the loop&#8217;s execution in a certain manner.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Statement<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>break<\/code><\/td><td>Terminate the current loop. Use the break statement to come out of the loop instantly.<\/td><\/tr><tr><td><code>continue<\/code><\/td><td>Skip the current iteration of a loop and move to the next iteration<\/td><\/tr><tr><td><code>pass<\/code><\/td><td>Do nothing. Ignore the condition in which it occurred and proceed to run the program as usual<\/td><\/tr><\/tbody><\/table><figcaption>Loop control statements in Python<\/figcaption><\/figure>\n\n\n\n<p>The <code>break<\/code> and <code>continue<\/code> statements are part of a&nbsp;<a href=\"https:\/\/pynative.com\/python-control-flow-statements\/\">control flow statements<\/a> that helps you to understand the <a href=\"https:\/\/pynative.com\/python\/basics\/\">basics of Python<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-yoast-seo-table-of-contents yoast-table-of-contents\"><h2>Table of contents<\/h2><ul><li><a href=\"#h-break-statement-in-python\" data-level=\"2\">Break Statement in Python<\/a><ul><li><a href=\"#h-example-break-for-loop-in-python\" data-level=\"3\">Example: Break for loop in Python<\/a><\/li><li><a href=\"#h-how-break-statement-works\" data-level=\"3\">How break statement works<\/a><\/li><li><a href=\"#h-example-break-while-loop\" data-level=\"3\">Example: Break while loop<\/a><\/li><li><a href=\"#h-break-nested-loop-in-python\" data-level=\"3\">Break Nested Loop in Python<\/a><\/li><li><a href=\"#h-break-outer-loop-in-python\" data-level=\"3\">Break Outer loop in Python<\/a><\/li><\/ul><\/li><li><a href=\"#h-continue-statement-in-python\" data-level=\"2\">Continue Statement in Python<\/a><ul><li><a href=\"#h-example-continue-statement-in-for-loop\" data-level=\"3\">Example: continue statement in for loop<\/a><\/li><li><a href=\"#h-how-continue-statement-works\" data-level=\"3\">How continue statement works<\/a><\/li><li><a href=\"#h-example-continue-statement-in-while-loop\" data-level=\"3\">Example: continue statement in while loop<\/a><\/li><li><a href=\"#h-continue-statement-in-nested-loop\" data-level=\"3\">Continue Statement in Nested Loop<\/a><\/li><li><a href=\"#h-continue-statement-in-outer-loop\" data-level=\"3\">Continue Statement in Outer loop<\/a><\/li><\/ul><\/li><li><a href=\"#h-pass-statement-in-python\" data-level=\"2\">Pass Statement in Python<\/a><\/li><\/ul><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-break-statement-in-python\">Break Statement in Python<\/h2>\n\n\n\n<p><strong>The <code>break<\/code> statement is used inside the loop to exit out of the loop<\/strong>. In Python, when a <code>break<\/code> statement is encountered inside a loop, the loop is immediately terminated, and the program control transfer to the next statement following the loop.<\/p>\n\n\n\n<p>In simple words, A <code>break<\/code> keyword terminates the loop containing it. If the <code>break<\/code> statement is used inside a nested loop (loop inside another loop), it will terminate the innermost loop. <\/p>\n\n\n\n<p><strong>For example<\/strong>, you are searching a specific email inside a file. You started reading a file line by line using a loop. When you found an email, you can stop the loop using the break statement.<\/p>\n\n\n\n<p>We can use Python <code>break<\/code> statement in both for loop and while loop. It is helpful to terminate the loop as soon as the condition is fulfilled instead of doing the remaining iterations. It reduces execution time.<\/p>\n\n\n\n<p><strong>Syntax of <code>break<\/code><\/strong>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">break<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"475\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/break-loop-in-python.png\" alt=\"Break loop in Python\" class=\"wp-image-9486\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/break-loop-in-python.png 786w, https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/break-loop-in-python-300x181.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/break-loop-in-python-768x464.png 768w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><figcaption>Break loop in Python<\/figcaption><\/figure><\/div>\n\n\n\n<p>Let us see the usage of the <code>break<\/code> statement with an example.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-break-for-loop-in-python\"><strong>Example<\/strong>: Break for loop in Python<\/h3>\n\n\n\n<p>In this example, we will iterate numbers from a <a href=\"https:\/\/pynative.com\/python-lists\/\">list<\/a> using a <a href=\"https:\/\/pynative.com\/python-for-loop\/\">for loop<\/a>, and if we found a number greater than 100, we will break the loop.<\/p>\n\n\n\n<p>Use the <a href=\"https:\/\/pynative.com\/python-control-flow-statements\/#h-if-statement-in-python\">if condition<\/a> to terminate the loop. If the condition evaluates to true, then the loop will terminate. Else loop will continue to work until the main loop condition is true.<\/p>\n\n\n<div class=\"hljstoolbar\"><pre id=\"code1\"  class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">numbers = &#91;<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">40<\/span>, <span class=\"hljs-number\">120<\/span>, <span class=\"hljs-number\">230<\/span>]\n<span class=\"hljs-keyword\">for<\/span> i <span class=\"hljs-keyword\">in<\/span> numbers:\n    <span class=\"hljs-keyword\">if<\/span> i &gt; <span class=\"hljs-number\">100<\/span>:\n        <span class=\"hljs-keyword\">break<\/span>\n    print(<span class=\"hljs-string\">'current number'<\/span>, i)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code1', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><button class=\"hljs-run-button\" onclick=\"run_code('code1');\"><i class=\"far fa-play-circle\" aria-hidden=\"true\"><\/i> Run<\/button><\/div>\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">curret number 10\ncurret number 40<\/pre>\n\n\n\n<p><strong>Note<\/strong>: As you can see in the output, we got numbers less than 100 because we used the <code>break<\/code> statement inside the if condition (the number is greater than 100) to terminate the loop<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-break-statement-works\">How break statement works<\/h3>\n\n\n\n<p>We used a <code>break<\/code> statement along with if statement. Whenever a specific condition occurs and a <code>break<\/code> statement is encountered inside a loop, the loop is immediately terminated, and the program control transfer to the next statement following the loop.<\/p>\n\n\n\n<p>Let&#8217;s understand the above example iteration by iteration.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>In the first iteration of the loop, 10 gets printed, and the condition <code>i &gt; 100<\/code> is checked. Since the value of <a href=\"https:\/\/pynative.com\/python-variables\/\">variable<\/a> <code>i<\/code> is 10, the condition becomes false.<\/li><li>In the second iteration of the loop, 20 gets printed again, and the condition <code>i &gt; 100<\/code> is checked. Since the value of <code>i<\/code> is 40, the condition becomes false.<\/li><li>In the third iteration of the loop, the condition<code> i &gt; 100<\/code> becomes true, and the <code>break<\/code> statement terminates the loop<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-break-while-loop\"><strong>Example<\/strong>: Break while loop<\/h3>\n\n\n\n<p>We can use the <code>break<\/code> statement inside a <a href=\"https:\/\/pynative.com\/python-while-loop\/\">while loop<\/a> using the same approach.<\/p>\n\n\n\n<p>Write a while loop to display each character from a string and if a character is a space then terminate the loop.<\/p>\n\n\n\n<p>Use the if condition to stop the while loop. If the current character is space then the condition evaluates to true, then the <code>break<\/code> statement will execute and the loop will terminate. Else loop will continue to work until the main loop condition is true.<\/p>\n\n\n<div class=\"hljstoolbar\"><pre id=\"code2\"  class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">name = <span class=\"hljs-string\">'Jesaa29 Roy'<\/span>\n\nsize = len(name)\ni = <span class=\"hljs-number\">0<\/span>\n<span class=\"hljs-comment\"># iterate loop till the last character<\/span>\n<span class=\"hljs-keyword\">while<\/span> i &lt; size:\n    <span class=\"hljs-comment\"># break loop if current character is space<\/span>\n    <span class=\"hljs-keyword\">if<\/span> name&#91;i].isspace():\n        <span class=\"hljs-keyword\">break<\/span>\n    <span class=\"hljs-comment\"># print current character<\/span>\n    print(name&#91;i], end=<span class=\"hljs-string\">' '<\/span>)\n    i = i + <span class=\"hljs-number\">1<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code2', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><button class=\"hljs-run-button\" onclick=\"run_code('code2');\"><i class=\"far fa-play-circle\" aria-hidden=\"true\"><\/i> Run<\/button><\/div>\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"361\" height=\"487\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/flowchart-of-break-statement.png\" alt=\"Flow chart of a break statement\" class=\"wp-image-9480\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/flowchart-of-break-statement.png 361w, https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/flowchart-of-break-statement-222x300.png 222w\" sizes=\"auto, (max-width: 361px) 100vw, 361px\" \/><figcaption>Flow chart of a break statement<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-break-nested-loop-in-python\">Break Nested Loop in Python<\/h3>\n\n\n\n<p>To terminate the nested loop, use a <code>break<\/code> statement inside the inner loop. Let&#8217;s see the example.<\/p>\n\n\n\n<p>In the following example, we have two loops, the outer loop, and the inner loop. The outer for loop iterates the first 10 numbers using the <a href=\"https:\/\/pynative.com\/python-range-function\/\">range()<\/a> function, and the internal loop prints the multiplication table of each number.<\/p>\n\n\n\n<p>But if the current number of both the outer loop and the inner loop is greater than 5 then terminate the inner loop using the break statement.<\/p>\n\n\n\n<p><strong>Example<\/strong>: Break nested loop<\/p>\n\n\n<div class=\"hljstoolbar\"><pre id=\"code3\"  class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">for<\/span> i <span class=\"hljs-keyword\">in<\/span> range(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">11<\/span>):\n    print(<span class=\"hljs-string\">'Multiplication table of'<\/span>, i)\n    <span class=\"hljs-keyword\">for<\/span> j <span class=\"hljs-keyword\">in<\/span> range(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">11<\/span>):\n        <span class=\"hljs-comment\"># condition to break inner loop<\/span>\n        <span class=\"hljs-keyword\">if<\/span> i &gt; <span class=\"hljs-number\">5<\/span> <span class=\"hljs-keyword\">and<\/span> j &gt; <span class=\"hljs-number\">5<\/span>:\n            <span class=\"hljs-keyword\">break<\/span>\n        print(i * j, end=<span class=\"hljs-string\">' '<\/span>)\n    print(<span class=\"hljs-string\">''<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code3', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><button class=\"hljs-run-button\" onclick=\"run_code('code3');\"><i class=\"far fa-play-circle\" aria-hidden=\"true\"><\/i> Run<\/button><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-break-outer-loop-in-python\">Break Outer loop in Python<\/h3>\n\n\n\n<p>To terminate the outside loop, use a <code>break<\/code> statement inside the outer loop. Let&#8217;s see the example.<\/p>\n\n\n\n<p>In the following example, we have two loops, the outer loop, and the inner loop. The outer loop iterates the first 10 numbers, and the internal loop prints the multiplication table of each number.<\/p>\n\n\n\n<p>But if the current number of the outer loop is greater than 5 then terminate the outer loop using the <code>break<\/code> statement.<\/p>\n\n\n\n<p><strong>Example<\/strong>: Break outer loop<\/p>\n\n\n<div class=\"hljstoolbar\"><pre id=\"code4\"  class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">for<\/span> i <span class=\"hljs-keyword\">in<\/span> range(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">11<\/span>):\n    <span class=\"hljs-comment\"># condition to break outer loop<\/span>\n    <span class=\"hljs-keyword\">if<\/span> i &gt; <span class=\"hljs-number\">5<\/span>:\n        <span class=\"hljs-keyword\">break<\/span>\n    print(<span class=\"hljs-string\">'Multiplication table of'<\/span>, i)\n    <span class=\"hljs-keyword\">for<\/span> j <span class=\"hljs-keyword\">in<\/span> range(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">11<\/span>):\n        print(i * j, end=<span class=\"hljs-string\">' '<\/span>)\n    print(<span class=\"hljs-string\">''<\/span>)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code4', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><button class=\"hljs-run-button\" onclick=\"run_code('code4');\"><i class=\"far fa-play-circle\" aria-hidden=\"true\"><\/i> Run<\/button><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-continue-statement-in-python\">Continue Statement in Python<\/h2>\n\n\n\n<p><strong>The <code>continue<\/code> statement skip the current iteration and move to the next iteration<\/strong>. In Python, when the <code>continue<\/code> statement is encountered inside the loop, it skips all the statements below it and immediately jumps to the next iteration.<\/p>\n\n\n\n<p>In simple words, the <code>continue<\/code> statement is used inside loops. Whenever the <code>continue<\/code> statement is encountered inside a loop, control directly jumps to the start of the loop for the next iteration, skipping the rest of the code present inside the loop\u2019s body for the current iteration.<\/p>\n\n\n\n<p>In some situations, it is helpful to skip executing some statement inside a loop&#8217;s body if a particular condition occurs and directly move to the next iteration.<\/p>\n\n\n\n<p><strong>Syntax of <code>continue<\/code><\/strong>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">continue<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Let us see the use of the <code>continue<\/code> statement with an example.<\/p>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"785\" height=\"435\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/python-continue-statement-in-loop.png\" alt=\"Python continue statement in loop\" class=\"wp-image-9487\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/python-continue-statement-in-loop.png 785w, https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/python-continue-statement-in-loop-300x166.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/python-continue-statement-in-loop-768x426.png 768w\" sizes=\"auto, (max-width: 785px) 100vw, 785px\" \/><figcaption>Python continue statement in loop<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-continue-statement-in-for-loop\">Example: continue statement in for loop<\/h3>\n\n\n\n<p>In this example, we will iterate numbers from a list using a for loop and calculate its square. If we found a number greater than 10, we will not calculate its square and directly jump to the next number.<\/p>\n\n\n\n<p>Use the if condition with the <code>continue<\/code> statement. If the condition evaluates to true, then the loop will move to the next iteration.<\/p>\n\n\n<div class=\"hljstoolbar\"><pre id=\"code5\"  class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">numbers = &#91;<span class=\"hljs-number\">2<\/span>, <span class=\"hljs-number\">3<\/span>, <span class=\"hljs-number\">11<\/span>, <span class=\"hljs-number\">7<\/span>]\n<span class=\"hljs-keyword\">for<\/span> i <span class=\"hljs-keyword\">in<\/span> numbers:\n    print(<span class=\"hljs-string\">'Current Number is'<\/span>, i)\n    <span class=\"hljs-comment\"># skip below statement if number is greater than 10<\/span>\n    <span class=\"hljs-keyword\">if<\/span> i &gt; <span class=\"hljs-number\">10<\/span>:\n        <span class=\"hljs-keyword\">continue<\/span>\n    square = i * i\n    print(<span class=\"hljs-string\">'Square of a current number is'<\/span>, square)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code5', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><button class=\"hljs-run-button\" onclick=\"run_code('code5');\"><i class=\"far fa-play-circle\" aria-hidden=\"true\"><\/i> Run<\/button><\/div>\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">Current Number <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-number\">2<\/span>\nSquare of a current number <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-number\">4<\/span>\nCurrent Number <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-number\">3<\/span>\nSquare of a current number <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-number\">9<\/span>\nCurrent Number <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-number\">11<\/span>\nCurrent Number <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-number\">7<\/span>\nSquare of a current number <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-number\">49<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>Note<\/strong>: As you can see in the output, we got square of 2, 3, and 7, but the loop ignored number 11 because we used the if condition to check if the number is greater than ten, and the condition evaluated to true, then loop skipped calculating the square of 11 and moved to the next number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-continue-statement-works\">How continue statement works<\/h3>\n\n\n\n<p>We used the <code>continue<\/code> statement along with the if statement. Whenever a specific condition occurs and the <code>continue<\/code> statement is encountered inside a loop, the loop immediately skips the remeaning body and move to the next iteration. <\/p>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"342\" height=\"482\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/flowchart-of-continue-statement.png\" alt=\"Flow chart of a continue statement\" class=\"wp-image-9481\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/flowchart-of-continue-statement.png 342w, https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/flowchart-of-continue-statement-213x300.png 213w\" sizes=\"auto, (max-width: 342px) 100vw, 342px\" \/><figcaption>Flow chart of a continue statement<\/figcaption><\/figure><\/div>\n\n\n\n<p>Let&#8217;s understand the above example iteration by iteration.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>In the first iteration of the loop, 4 gets printed, and the condition <code>i &gt; 10<\/code> is checked. Since the value of <code>i<\/code> is 2, the condition becomes false.<\/li><li>In the second iteration of the loop, 9 gets printed, and the condition <code>i &gt; 10<\/code> is checked. Since the value of <code>i<\/code> is 9, the condition becomes false.<\/li><li>In the third iteration of the loop, the condition<code> i &gt; 10<\/code> becomes true, and the <code>continue<\/code> statement skips the remaining statements and moves to the next iteration of the loop<\/li><li>In the second iteration of the loop, 49 gets printed, and the condition <code>i &gt; 10<\/code> is checked. Since the value of <code>i<\/code> is 7, the condition becomes false.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-continue-statement-in-while-loop\"><strong>Example<\/strong>: continue statement in while loop<\/h3>\n\n\n\n<p>We can also use the <code>continue<\/code> statement inside a while loop. Let&#8217;s understand this with an example.<\/p>\n\n\n\n<p>Write a while loop to display each character from a string and if a character is a space, then don&#8217;t display it and move to the next character.<\/p>\n\n\n\n<p>Use the if condition with the <code>continue<\/code> statement to jump to the next iteration. If the current character is space, then the condition evaluates to true, then the <code>continue<\/code> statement will execute, and the loop will move to the next iteration by skipping the remeaning body.<\/p>\n\n\n<div class=\"hljstoolbar\"><pre id=\"code6\"  class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">name = <span class=\"hljs-string\">'Je sa a'<\/span>\n\nsize = len(name)\ni = <span class=\"hljs-number\">-1<\/span>\n<span class=\"hljs-comment\"># iterate loop till the last character<\/span>\n<span class=\"hljs-keyword\">while<\/span> i &lt; size - <span class=\"hljs-number\">1<\/span>:\n    i = i + <span class=\"hljs-number\">1<\/span>\n    <span class=\"hljs-comment\"># skip loop body if current character is space<\/span>\n    <span class=\"hljs-keyword\">if<\/span> name&#91;i].isspace():\n        <span class=\"hljs-keyword\">continue<\/span>\n    <span class=\"hljs-comment\"># print current character<\/span>\n    print(name&#91;i], end=<span class=\"hljs-string\">' '<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code6', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><button class=\"hljs-run-button\" onclick=\"run_code('code6');\"><i class=\"far fa-play-circle\" aria-hidden=\"true\"><\/i> Run<\/button><\/div>\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">J e s a a <\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-continue-statement-in-nested-loop\">Continue Statement in Nested Loop<\/h3>\n\n\n\n<p>To skip the current iteration of the nested loop, use the <code>continue<\/code> statement inside the body of the inner loop. Let&#8217;s see the example.<\/p>\n\n\n\n<p>In the following example, we have the outer loop and the inner loop. The outer loop iterates the first 10 numbers, and the internal loop prints the multiplication table of each number.<\/p>\n\n\n\n<p>But if the current number of the inner loop is equal to 5, then skip the current iteration and move to the next iteration of the inner loop using the <code>continue<\/code> statement.<\/p>\n\n\n\n<p><strong>Example<\/strong>: continue statement in nested loop<\/p>\n\n\n<div class=\"hljstoolbar\"><pre id=\"code7\"  class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">for<\/span> i <span class=\"hljs-keyword\">in<\/span> range(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">11<\/span>):\n    print(<span class=\"hljs-string\">'Multiplication table of'<\/span>, i)\n    <span class=\"hljs-keyword\">for<\/span> j <span class=\"hljs-keyword\">in<\/span> range(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">11<\/span>):\n        <span class=\"hljs-comment\"># condition to skip current iteration<\/span>\n        <span class=\"hljs-keyword\">if<\/span> j == <span class=\"hljs-number\">5<\/span>:\n            <span class=\"hljs-keyword\">continue<\/span>\n        print(i * j, end=<span class=\"hljs-string\">' '<\/span>)\n    print(<span class=\"hljs-string\">''<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code7', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><button class=\"hljs-run-button\" onclick=\"run_code('code7');\"><i class=\"far fa-play-circle\" aria-hidden=\"true\"><\/i> Run<\/button><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-continue-statement-in-outer-loop\">Continue Statement in Outer loop<\/h3>\n\n\n\n<p>To skip the current iteration of an outside loop, use the <code>continue<\/code> statement inside the outer loop. Let&#8217;s see the example<\/p>\n\n\n\n<p>In the following example, The outer loop iterates the first 10 numbers, and the internal loop prints the multiplication table of each number.<\/p>\n\n\n\n<p>But if the current number of the outer loop is even, then skip the current iteration of the outer loop and move to the next iteration.<\/p>\n\n\n\n<p><strong>Note<\/strong>: If we skip the current iteration of an outer loop, the inner loop will not be executed for that iteration because the inner loop is part of the body of an outer loop.<\/p>\n\n\n\n<p><strong>Example<\/strong>: <code>continue <\/code>statement in outer loop<\/p>\n\n\n<div class=\"hljstoolbar\"><pre id=\"code8\"  class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">for<\/span> i <span class=\"hljs-keyword\">in<\/span> range(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">11<\/span>):\n    <span class=\"hljs-comment\"># condition to skip iteration<\/span>\n    <span class=\"hljs-comment\"># Don't print multiplication table of even numbers<\/span>\n    <span class=\"hljs-keyword\">if<\/span> i % <span class=\"hljs-number\">2<\/span> == <span class=\"hljs-number\">0<\/span>:\n        <span class=\"hljs-keyword\">continue<\/span>\n    print(<span class=\"hljs-string\">'Multiplication table of'<\/span>, i)\n    <span class=\"hljs-keyword\">for<\/span> j <span class=\"hljs-keyword\">in<\/span> range(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">11<\/span>):\n        print(i * j, end=<span class=\"hljs-string\">' '<\/span>)\n    print(<span class=\"hljs-string\">''<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code8', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><button class=\"hljs-run-button\" onclick=\"run_code('code8');\"><i class=\"far fa-play-circle\" aria-hidden=\"true\"><\/i> Run<\/button><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-pass-statement-in-python\">Pass Statement in Python<\/h2>\n\n\n\n<p>The <code>pass<\/code> is the keyword In Python, which won&#8217;t do anything. Sometimes there is a situation in programming where we need to define a syntactically empty block. We can define that block with the pass keyword.<\/p>\n\n\n\n<p>A <code>pass<\/code> statement is a Python null statement. When the interpreter finds a pass statement in the program, it returns no operation. Nothing happens when the <code>pass<\/code> statement is executed.<\/p>\n\n\n\n<p>It is useful in a situation where we are implementing new methods or also in exception handling. It plays a role like a placeholder.<\/p>\n\n\n\n<p><strong>Syntax of <code>pass<\/code> statement:<\/strong><\/p>\n\n\n<pre id=\"syntax\" class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">for<\/span> element <span class=\"hljs-keyword\">in<\/span> sequence:\n    <span class=\"hljs-keyword\">if<\/span> condition:\n        <span class=\"hljs-keyword\">pass<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>Example<\/strong><\/p>\n\n\n<div class=\"hljstoolbar\"><pre id=\"code9\"  class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">months = &#91;<span class=\"hljs-string\">'January'<\/span>, <span class=\"hljs-string\">'June'<\/span>, <span class=\"hljs-string\">'March'<\/span>, <span class=\"hljs-string\">'April'<\/span>]\n<span class=\"hljs-keyword\">for<\/span> mon <span class=\"hljs-keyword\">in<\/span> months:\n    <span class=\"hljs-keyword\">pass<\/span>\nprint(months)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code9', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><button class=\"hljs-run-button\" onclick=\"run_code('code9');\"><i class=\"far fa-play-circle\" aria-hidden=\"true\"><\/i> Run<\/button><\/div>\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">['January', 'June', 'March', 'April']<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this article, you will learn how to use \u200ethe break, continue and pass statements when working with loops in Python. We use break, continue statements to alter the loop&#8217;s execution in a certain manner. Statement Description break Terminate the current loop. Use the break statement to come out of the loop instantly. continue Skip [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[22,1],"tags":[32],"class_list":{"0":"post-9476","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python","7":"category-basics","8":"tag-python-basics","9":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Break, Continue, and Pass &#8211; PYnative<\/title>\n<meta name=\"description\" content=\"Learn to use the break, continue, and pass statements when working with loops in Python to alter the for loop and while loop execution.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/pynative.com\/python-break-continue-pass\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Break, Continue, and Pass\" \/>\n<meta property=\"og:description\" content=\"Learn to use the break, continue, and pass statements when working with loops in Python to alter the for loop and while loop execution.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/pynative.com\/python-break-continue-pass\/\" \/>\n<meta property=\"og:site_name\" content=\"PYnative\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-03T12:14:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-06T03:57:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/break-loop-in-python.png\" \/>\n<meta name=\"author\" content=\"Vishal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@PyNative\" \/>\n<meta name=\"twitter:site\" content=\"@PyNative\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/\"},\"author\":{\"name\":\"Vishal\",\"@id\":\"https:\\\/\\\/pynative.com\\\/#\\\/schema\\\/person\\\/64b55d5bde2265918c5a9931de4de71f\"},\"headline\":\"Python Break, Continue, and Pass\",\"datePublished\":\"2021-06-03T12:14:23+00:00\",\"dateModified\":\"2021-06-06T03:57:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/\"},\"wordCount\":1612,\"commentCount\":10,\"publisher\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/#\\\/schema\\\/person\\\/64b55d5bde2265918c5a9931de4de71f\"},\"image\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/break-loop-in-python.png\",\"keywords\":[\"Python Basics\"],\"articleSection\":[\"Python\",\"Python Basics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/#respond\"]}],\"accessibilityFeature\":[\"tableOfContents\"]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/\",\"url\":\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/\",\"name\":\"Python Break, Continue, and Pass &#8211; PYnative\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/break-loop-in-python.png\",\"datePublished\":\"2021-06-03T12:14:23+00:00\",\"dateModified\":\"2021-06-06T03:57:57+00:00\",\"description\":\"Learn to use the break, continue, and pass statements when working with loops in Python to alter the for loop and while loop execution.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/#primaryimage\",\"url\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/break-loop-in-python.png\",\"contentUrl\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/break-loop-in-python.png\",\"width\":786,\"height\":475,\"caption\":\"Break loop in Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/pynative.com\\\/python-break-continue-pass\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/pynative.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\\\/\\\/pynative.com\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Break, Continue, and Pass\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/pynative.com\\\/#website\",\"url\":\"https:\\\/\\\/pynative.com\\\/\",\"name\":\"PYnative\",\"description\":\"Python Programming\",\"publisher\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/#\\\/schema\\\/person\\\/64b55d5bde2265918c5a9931de4de71f\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/pynative.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/pynative.com\\\/#\\\/schema\\\/person\\\/64b55d5bde2265918c5a9931de4de71f\",\"name\":\"Vishal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/vishalHule.jpg\",\"url\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/vishalHule.jpg\",\"contentUrl\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/vishalHule.jpg\",\"width\":968,\"height\":1065,\"caption\":\"Vishal\"},\"logo\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/vishalHule.jpg\"},\"description\":\"Founder of PYnative.com. I am a Python developer and I love to write articles to help developers. | All the best for your future Python endeavors!\",\"sameAs\":[\"https:\\\/\\\/pynative.com\"]}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Break, Continue, and Pass &#8211; PYnative","description":"Learn to use the break, continue, and pass statements when working with loops in Python to alter the for loop and while loop execution.","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:\/\/pynative.com\/python-break-continue-pass\/","og_locale":"en_US","og_type":"article","og_title":"Python Break, Continue, and Pass","og_description":"Learn to use the break, continue, and pass statements when working with loops in Python to alter the for loop and while loop execution.","og_url":"https:\/\/pynative.com\/python-break-continue-pass\/","og_site_name":"PYnative","article_published_time":"2021-06-03T12:14:23+00:00","article_modified_time":"2021-06-06T03:57:57+00:00","og_image":[{"url":"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/break-loop-in-python.png","type":"","width":"","height":""}],"author":"Vishal","twitter_card":"summary_large_image","twitter_creator":"@PyNative","twitter_site":"@PyNative","twitter_misc":{"Written by":"Vishal","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/pynative.com\/python-break-continue-pass\/#article","isPartOf":{"@id":"https:\/\/pynative.com\/python-break-continue-pass\/"},"author":{"name":"Vishal","@id":"https:\/\/pynative.com\/#\/schema\/person\/64b55d5bde2265918c5a9931de4de71f"},"headline":"Python Break, Continue, and Pass","datePublished":"2021-06-03T12:14:23+00:00","dateModified":"2021-06-06T03:57:57+00:00","mainEntityOfPage":{"@id":"https:\/\/pynative.com\/python-break-continue-pass\/"},"wordCount":1612,"commentCount":10,"publisher":{"@id":"https:\/\/pynative.com\/#\/schema\/person\/64b55d5bde2265918c5a9931de4de71f"},"image":{"@id":"https:\/\/pynative.com\/python-break-continue-pass\/#primaryimage"},"thumbnailUrl":"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/break-loop-in-python.png","keywords":["Python Basics"],"articleSection":["Python","Python Basics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/pynative.com\/python-break-continue-pass\/#respond"]}],"accessibilityFeature":["tableOfContents"]},{"@type":"WebPage","@id":"https:\/\/pynative.com\/python-break-continue-pass\/","url":"https:\/\/pynative.com\/python-break-continue-pass\/","name":"Python Break, Continue, and Pass &#8211; PYnative","isPartOf":{"@id":"https:\/\/pynative.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/pynative.com\/python-break-continue-pass\/#primaryimage"},"image":{"@id":"https:\/\/pynative.com\/python-break-continue-pass\/#primaryimage"},"thumbnailUrl":"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/break-loop-in-python.png","datePublished":"2021-06-03T12:14:23+00:00","dateModified":"2021-06-06T03:57:57+00:00","description":"Learn to use the break, continue, and pass statements when working with loops in Python to alter the for loop and while loop execution.","breadcrumb":{"@id":"https:\/\/pynative.com\/python-break-continue-pass\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/pynative.com\/python-break-continue-pass\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pynative.com\/python-break-continue-pass\/#primaryimage","url":"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/break-loop-in-python.png","contentUrl":"https:\/\/pynative.com\/wp-content\/uploads\/2021\/06\/break-loop-in-python.png","width":786,"height":475,"caption":"Break loop in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/pynative.com\/python-break-continue-pass\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/pynative.com\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/pynative.com\/python\/"},{"@type":"ListItem","position":3,"name":"Python Break, Continue, and Pass"}]},{"@type":"WebSite","@id":"https:\/\/pynative.com\/#website","url":"https:\/\/pynative.com\/","name":"PYnative","description":"Python Programming","publisher":{"@id":"https:\/\/pynative.com\/#\/schema\/person\/64b55d5bde2265918c5a9931de4de71f"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/pynative.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/pynative.com\/#\/schema\/person\/64b55d5bde2265918c5a9931de4de71f","name":"Vishal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/vishalHule.jpg","url":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/vishalHule.jpg","contentUrl":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/vishalHule.jpg","width":968,"height":1065,"caption":"Vishal"},"logo":{"@id":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/vishalHule.jpg"},"description":"Founder of PYnative.com. I am a Python developer and I love to write articles to help developers. | All the best for your future Python endeavors!","sameAs":["https:\/\/pynative.com"]}]}},"featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"Vishal","author_link":"https:\/\/pynative.com\/author\/vishal\/"},"_links":{"self":[{"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/posts\/9476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/comments?post=9476"}],"version-history":[{"count":0,"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/posts\/9476\/revisions"}],"wp:attachment":[{"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/media?parent=9476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/categories?post=9476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/tags?post=9476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}