{"id":750,"date":"2021-04-30T11:56:29","date_gmt":"2021-04-30T06:26:29","guid":{"rendered":"https:\/\/cbsepython.in\/?p=750"},"modified":"2023-12-28T09:56:01","modified_gmt":"2023-12-28T04:26:01","slug":"jump-statements-in-python","status":"publish","type":"post","link":"https:\/\/cbsepython.in\/jump-statements-in-python\/","title":{"rendered":"JUMP Statements in Python for Class 12"},"content":{"rendered":"<p>JUMP STATEMENTS<\/p>\n<p>Looping allows a user to program and repeat tasks efficiently. In certain situations, when some particular condition occurs, a user may want to exit from a loop (come out of the loop forever) or skip some statements of the loop before continuing further in the loop. These requirements can be taken care of by use of break and continue control statements respectively. Python provides these jump statements as a tool to give more flexibility to the programmer to control logic of loops.<\/p>\n<p>Jump statements in Python are used to change the normal flow of execution of a program. There are three types of jump statements in Python: <code>break<\/code>, <code>continue<\/code>, and <code>pass<\/code>.<\/p>\n<p>&nbsp;<\/p>\n<p>1. <code>break<\/code>: The <code>break<\/code> statement is used to terminate the current loop prematurely. When a <code>break<\/code> statement is encountered inside a loop, the loop is immediately terminated, and program execution continues with the statement following the loop.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Example of break statement\r\n\r\nnumbers = [1, 2, 3, 4, 5]\r\n\r\nfor num in numbers:\r\n    if num == 3:\r\n        break\r\n    print(num)\r\n    \r\n# Output: \r\n# 1\r\n# 2\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>In this example, we have a list of numbers and a <code>for<\/code> loop that iterates over each number in the list. When the loop encounters the number <code>3<\/code>, the <code>break<\/code> statement is executed, and the loop is terminated. The program then continues with the statement following the loop.<\/p>\n<p>&nbsp;<\/p>\n<p>2. <code>continue<\/code>: The <code>continue<\/code> statement is used to skip the current iteration of a loop and continue with the next iteration. When a <code>continue<\/code> statement is encountered inside a loop, the current iteration is terminated, and the loop proceeds with the next iteration.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Example of continue statement\r\n\r\nnumbers = [1, 2, 3, 4, 5]\r\n\r\nfor num in numbers:\r\n    if num == 3:\r\n        continue\r\n    print(num)\r\n    \r\n# Output: \r\n# 1\r\n# 2\r\n# 4\r\n# 5\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>In this example, we have a list of numbers and a <code>for<\/code> loop that iterates over each number in the list. When the loop encounters the number <code>3<\/code>, the <code>continue<\/code> statement is executed, and the current iteration is terminated. The loop then proceeds with the next iteration.<\/p>\n<p>&nbsp;<\/p>\n<p>3. <code>pass<\/code>: The <code>pass<\/code> statement is used as a placeholder when a statement is required syntactically but no code needs to be executed. It is often used as a placeholder for functions or classes that will be implemented later.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Example of pass statement\r\n\r\ndef my_function():\r\n    pass\r\n    \r\nclass MyClass:\r\n    pass\r\n<\/pre>\n<p>In this example, we have a function and a class definition that both contain the <code>pass<\/code> statement. This indicates that the function and class will be implemented later, but we want to define them syntactically correct.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">x = 10\r\n\r\nif x &gt; 5:\r\n    pass\r\nelse:\r\n    print(\"x is not greater than 5\")\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>In this example, we use <code>pass<\/code> as a placeholder inside an <code>if<\/code> statement. If <code>x<\/code> is greater than 5, the <code>pass<\/code> statement is executed, and the program continues with the statement following the <code>if<\/code> block. If <code>x<\/code> is not greater than 5, the <code>print<\/code> statement is executed instead.<\/p>\n<p>In this case, the <code>pass<\/code> statement is not necessary and could be removed without changing the program&#8217;s behavior. However, <code>pass<\/code> can be useful as a placeholder when you want to indicate that code will be added later or as a way to temporarily disable a block of code during development.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JUMP STATEMENTS Looping allows a user to program and repeat tasks efficiently. In certain situations, when some particular condition occurs, a user may want to exit from a loop (come out of the loop forever) or skip some statements of the loop before continuing further in the loop. These requirements can be taken care of [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-750","post","type-post","status-publish","format-standard","hentry","category-cbse-computer-science-with-python-class-12"],"_links":{"self":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/comments?post=750"}],"version-history":[{"count":0,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/750\/revisions"}],"wp:attachment":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/media?parent=750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/categories?post=750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/tags?post=750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}