{"id":66824,"date":"2022-07-01T07:45:32","date_gmt":"2022-07-01T07:45:32","guid":{"rendered":"https:\/\/itsourcecode.com\/?p=66824"},"modified":"2023-11-23T02:47:42","modified_gmt":"2023-11-23T02:47:42","slug":"loop-control-statements-in-python","status":"publish","type":"post","link":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/","title":{"rendered":"Loops in Python: Exploring For, While, and Nested Loops"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-what-are-loops-in-python\"><strong>What are Loops in Python?<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Loops <\/strong>are used to do the same thing over and over until a certain condition is met.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Loops <\/strong>are programming constructs that allow you to repeatedly execute a block of code based on a certain condition.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Loops <\/strong>are used to automate repetitive tasks and iterate over collections of data.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>The diagram below is the <strong>structure of a loop statement<\/strong>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Structure-of-Loops-in-Python.png\"><img loading=\"lazy\" decoding=\"async\" width=\"396\" height=\"423\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Structure-of-Loops-in-Python.png\" alt=\"Structure of loop statement\" class=\"wp-image-66923\" srcset=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Structure-of-Loops-in-Python.png 396w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Structure-of-Loops-in-Python-281x300.png 281w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/a><figcaption class=\"wp-element-caption\">Structure of loop statement<\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-why-do-we-use-loop-in-python\"><strong>Why do we use Loop in Python?<\/strong><\/h2>\n\n\n\n<p>The reason <strong>why we use loops in Python<\/strong> is that <strong>loops<\/strong> are essential in any programming language since they allow you to repeatedly execute a section of code.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>You will frequently encounter circumstances in which you need to reuse a piece of code, but you do not want to write the same line of code many times.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-types-of-loops-in-python\"><strong>Types of Loops in Python<\/strong><\/h2>\n\n\n\n<p>The following is a list of the <strong>different types of loops in Python<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>For Loops<\/strong><\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>While Loops<\/strong><\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Nested Loops<\/strong><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-for-loops-in-python\"><strong>1. For Loops in Python<\/strong><\/h3>\n\n\n\n<p class=\"tw-highlight-padding tw-link-hover-underline\"><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\"><strong>For Loops<\/strong><\/mark> in Python iterates over a series (<a href=\"https:\/\/itsourcecode.com\/python-tutorial\/lists-in-python-with-examples\/\">list<\/a>, <a href=\"https:\/\/itsourcecode.com\/python-tutorial\/tuples-in-python-operators-and-functions-with-examples\/\">tuple<\/a>, <a href=\"https:\/\/itsourcecode.com\/python-tutorial\/what-is-set-in-python-with-example\/\">set<\/a>, <a href=\"https:\/\/itsourcecode.com\/python-tutorial\/is-dictionary-mutable-in-python\/\">dictionary<\/a>, and <a href=\"https:\/\/itsourcecode.com\/python-tutorial\/python-strings\/\">string<\/a>).<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"tw-highlight-padding\">This is more like the iterator function in other object-oriented programming languages than the <strong>for <\/strong>keyword in other languages.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-syntax\"><strong>Syntax<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">The following code below is the&nbsp;<strong><code><mark style=\"background-color:var(--base-3);color:#ff0202\" class=\"has-inline-color\">for<\/mark><\/code> <\/strong>loops syntax in Python:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>for iterating_var in sequence:\n    #execute your code<\/strong><\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-flow-diagram\"><strong>Flow Diagram<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">Below is the <mark style=\"background-color:var(--base-3);color:#fd0202\" class=\"has-inline-color\"><strong>for<\/strong><\/mark> loops flow diagram:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-For-Loop-Flow-Diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"396\" height=\"423\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-For-Loop-Flow-Diagram-1.png\" alt=\"For Loops Flow Diagram in Python\" class=\"wp-image-66952\" srcset=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-For-Loop-Flow-Diagram-1.png 396w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-For-Loop-Flow-Diagram-1-281x300.png 281w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/a><figcaption class=\"wp-element-caption\">For Loops Flow Diagram<\/figcaption><\/figure><\/div>\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-examples\"><strong>Examples<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">Here are some of <strong><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">for<\/mark> <\/strong>loops examples:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>months = &#91;\"Jan\", \"Feb\", \"Mar\"]\nfor a in months:\n    print(a)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You can test the above example here!<\/strong>\u00a0\u27a1<a href=\"https:\/\/itsourcecode.com\/python-compiler\/\"><strong>Python Online Compiler<\/strong><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Jan\nFeb\nMar<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"tw-highlight-padding\">The <strong><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">for<\/mark> <\/strong>loop doesn&#8217;t need you to set up an indexing variable first.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Even <mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\"><strong>strings<\/strong><\/mark>, which are made up of a series of characters, are iterable objects.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for a in \"itsourcecode\":\n  print(a)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>i\nt\ns\no\nu\nr\nc\ne\nc\no\nd\ne<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-else-statements-in-for-loops\"><strong>Else Statements in For Loops<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">Like <a href=\"https:\/\/itsourcecode.com\/python-tutorial\/python-decision-making-statements\/\"><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\"><strong>if statements<\/strong><\/mark><\/a>, a <mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\"><strong>for loop<\/strong><\/mark> can have an optional <mark style=\"background-color:var(--base-3);color:#fa0000\" class=\"has-inline-color\"><strong>else statement<\/strong><\/mark> block. If there are no more items in the order used in the <mark style=\"background-color:var(--base-3);color:#fe0000\" class=\"has-inline-color\"><strong>for loop<\/strong><\/mark>, the <strong><mark style=\"background-color:var(--base-3);color:#fd0101\" class=\"has-inline-color\">else<\/mark> <\/strong>part is executed.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"tw-highlight-padding\">A <strong><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">for<\/mark> <\/strong>loop can be stopped with the <strong><mark style=\"background-color:var(--base-3);color:#fd0404\" class=\"has-inline-color\">break<\/mark> <\/strong>keyword. When this happens, the<strong> <mark style=\"background-color:rgba(0, 0, 0, 0);color:#f70000\" class=\"has-inline-color\">else<\/mark> <\/strong>part is ignored.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>So, the <strong><mark style=\"background-color:var(--base-3);color:#fd0909\" class=\"has-inline-color\">else<\/mark> <\/strong>part of a <strong><mark style=\"background-color:var(--base-3);color:#fa0707\" class=\"has-inline-color\">for<\/mark> <\/strong>loop runs if there is no break.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"h-example\"><strong>Example:<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>count = &#91;5, 4, 3, 2, 1]\n\nfor i in count:\n    print(i)\nelse:\n    print(\"No items left.\")<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You can test the above example here!<\/strong>\u00a0\u27a1<a href=\"https:\/\/itsourcecode.com\/python-compiler\/\"><strong>Python Online Compiler<\/strong><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"h-output\"><strong>Output:<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>5\n4\n3\n2\n1\nNo items left.<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-while-loops-in-python\"><strong>2. While Loops in Python<\/strong><\/h3>\n\n\n\n<p class=\"tw-highlight-padding\">A <mark style=\"background-color:rgba(0, 0, 0, 0);color:#fe0202\" class=\"has-inline-color\"><strong>while loop<\/strong><\/mark> statement in Python programming runs a target statement over and over as long as a given condition is true.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Most of the time, we use this loop when we don&#8217;t know ahead of time how many times to iterate.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-syntax-0\"><strong>Syntax:<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">The following code below is the <strong><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">while<\/mark> <\/strong>loops syntax in Python:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while expression:\n    #execute your code<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-flow-diagram-0\"><strong>Flow Diagram<\/strong><\/h4>\n\n\n\n<p>Below is the <strong><mark style=\"background-color:var(--base-3);color:#fd0202\" class=\"has-inline-color\">while<\/mark> <\/strong>loops flow diagram:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-While-Loop-Flow-Diagram.png\"><img loading=\"lazy\" decoding=\"async\" width=\"396\" height=\"423\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-While-Loop-Flow-Diagram.png\" alt=\"While Loops Flow Diagram in Python\" class=\"wp-image-66953\" srcset=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-While-Loop-Flow-Diagram.png 396w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-While-Loop-Flow-Diagram-281x300.png 281w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/a><figcaption class=\"wp-element-caption\">While Loops Flow Diagram<\/figcaption><\/figure><\/div>\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-examples-0\"><strong>Examples<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">Here is a <strong><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">while<\/mark> <\/strong>loop example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>i = 1\nwhile i &lt; 11:\n  print(i)\n  i += 1<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You can test the above example here!<\/strong>\u00a0\u27a1<a href=\"https:\/\/itsourcecode.com\/python-compiler\/\"><strong>Python Online Compiler<\/strong><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n2\n3\n4\n5\n6\n7\n8\n9\n10<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"tw-highlight-padding\">Don&#8217;t forget to increment<strong><code> <\/code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">i<\/mark><\/strong> or the loop will keep going forever.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"tw-highlight-padding\">In order to use the <strong>while <\/strong>loop, the right variables must be ready. In this case, we need to define an indexing variable<strong> i<\/strong> and set it to<strong> 1<\/strong>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-else-statement-in-while-loops\"><strong>Else Statement in While Loops<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">We can also use the <strong>else statement<\/strong> in while loops in Python just like in <strong>for loops<\/strong>.A <strong>break statement<\/strong> can be used to end the while loop. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"tw-highlight-padding\">In these situations, the <strong>else <\/strong>part is ignored. So, the else statements part of a while loop runs if the condition is false and there is no break.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"h-example-0\"><strong>Example:<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>count = 0\nwhile count &lt; 5:\n   print (count, \" is  less than 5\")\n   count = count + 1\nelse:\n   print (count, \" is not less than 5\")<\/strong><\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You can test the above example here!<\/strong>\u00a0\u27a1<a href=\"https:\/\/itsourcecode.com\/python-compiler\/\"><strong>Python Online Compiler<\/strong><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"h-output-0\"><strong>Output:<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>0  is  less than 5\n1  is  less than 5\n2  is  less than 5\n3  is  less than 5\n4  is  less than 5\n5  is not less than 5<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-nested-loops-in-python\"><strong>3. Nested Loops in Python<\/strong><\/h3>\n\n\n\n<p class=\"tw-highlight-padding\">A <mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\"><strong>nested loop<\/strong><\/mark> in Python is a <strong>loop<\/strong> that is inside the body of another loop. This means that every time the &#8220;outer loop&#8221; is run, the &#8220;inner loop&#8221; will be run once.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-syntax-1\"><strong>Syntax:<\/strong><\/h4>\n\n\n\n<p>Below is the <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#ff0000\" class=\"has-inline-color\">nested<\/mark> <\/strong>loop syntax in Python:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for iterating_var in sequence:\n    for iterating_var in sequence:\n       #execute your code\n          #execute your code<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-flow-diagram-1\"><strong>Flow Diagram<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">The following figure below is the <strong><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">nested<\/mark> <\/strong>loop flow diagram.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-Nested-Loop-Flow-Diagram.png\"><img loading=\"lazy\" decoding=\"async\" width=\"488\" height=\"442\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-Nested-Loop-Flow-Diagram.png\" alt=\"Nested Loop Flow Diagram in Python\" class=\"wp-image-66972\" srcset=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-Nested-Loop-Flow-Diagram.png 488w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/07\/Loops-in-Python-Nested-Loop-Flow-Diagram-300x272.png 300w\" sizes=\"auto, (max-width: 488px) 100vw, 488px\" \/><\/a><figcaption class=\"wp-element-caption\">Nested Loops Flow Diagram<\/figcaption><\/figure><\/div>\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-example-1\"><strong>Example<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">Below is the <strong><mark style=\"background-color:var(--base-3);color:#fe0000\" class=\"has-inline-color\">Nested<\/mark> <\/strong>Loops Example in Python:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>color = &#91;\"red\", \"blue\", \"yellow\"]\nthing = &#91;\"cellphone\", \"laptop\", \"shoe\"]\n\nfor a in color:\n  for b in thing:\n    print(a, b)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You can test the above example here!<\/strong>\u00a0\u27a1<a href=\"https:\/\/itsourcecode.com\/python-compiler\/\"><strong>Python Online Compiler<\/strong><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-output-1\"><strong>Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>red cellphone\nred laptop\nred shoe\nblue cellphone\nblue laptop\nblue shoe\nyellow cellphone\nyellow laptop\nyellow shoe<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-loop-control-statements-in-python\"><strong>Loop Control Statements in Python<\/strong><\/h2>\n\n\n\n<p><strong>Loop Control Statements<\/strong> in Python are used to alter the execution flow. These may be used to skip an iteration or terminate the process.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-types-of-loop-control-statements\"><strong>Types of Loop Control Statements<\/strong><\/h3>\n\n\n\n<p>Below are the different types of loop control statements in Python:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Break Statement<\/strong><\/li>\n\n\n\n<li><strong>Continue Statement<\/strong><\/li>\n\n\n\n<li><strong>Pass Statement<\/strong><\/li>\n<\/ol>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-1-break-statement\"><strong>1. Break Statement<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">The <mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\"><strong>break<\/strong><\/mark> statement halts execution and exits the loop, depending on the specified circumstance, <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Example:<\/strong> Make a list of odd numbers between 1 and 20. (use <mark style=\"background-color:var(--base-3);color:#fa0404\" class=\"has-inline-color\"><strong>while<\/strong><\/mark><code><mark style=\"background-color:var(--base);color:#fa0404\" class=\"has-inline-color\">, <\/mark><\/code><mark style=\"background-color:var(--base-3);color:#fa0404\" class=\"has-inline-color\"><strong>break<\/strong><\/mark>)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>num = 1\nodd_nums = &#91;]\nwhile num:\n    if num % 2 != 0:\n        odd_nums.append(num)\n    if num &gt;=20:\n        break\n    num += 1\nprint(\"Odd numbers: \", odd_nums)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You can test the above example here!<\/strong>\u00a0\u27a1<a href=\"https:\/\/itsourcecode.com\/python-compiler\/\"><strong>Python Online Compiler<\/strong><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Odd numbers:  &#91;1, 3, 5, 7, 9, 11, 13, 15, 17, 19]<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-2-continue-statement\"><strong>2. Continue Statement<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">The <strong><mark style=\"background-color:var(--base-3);color:#fb0202\" class=\"has-inline-color\">continue<\/mark> <\/strong>statement skips the current iteration and lets the loop move on to the next one when the condition is met. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"tw-highlight-padding\">It doesn&#8217;t take control out of the loop unless you put the <strong><mark style=\"background-color:rgba(0, 0, 0, 0);color:#fb0404\" class=\"has-inline-color\">break<\/mark> <\/strong>statement outside of the loop.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Example:<\/strong> If the current number is 6, skip the iteration (use <mark style=\"background-color:var(--base-3);color:#f60505\" class=\"has-inline-color\"><strong>while<\/strong><\/mark><code><mark style=\"background-color:var(--base-3);color:#f60505\" class=\"has-inline-color\">,<\/mark><\/code><mark style=\"background-color:var(--base-3);color:#f60505\" class=\"has-inline-color\"><strong>continue<\/strong><\/mark>)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>num = 0\nwhile num &lt; 10:\n    num += 1\n    if num == 6:\n        continue\n    print(num)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You can test the above example here!<\/strong>\u00a0\u27a1<a href=\"https:\/\/itsourcecode.com\/python-compiler\/\"><strong>Python Online Compiler<\/strong><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n2\n3\n4\n5\n7\n8\n9\n10<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-3-pass-statement\"><strong>3. Pass Statement<\/strong><\/h4>\n\n\n\n<p class=\"tw-highlight-padding\">The <strong><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">pass<\/mark> <\/strong>statement is used in Python when a statement is required syntactically but no command or code is to be run. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"tw-highlight-padding\">It doesn&#8217;t skip over or stop the execution. Instead, it moves on to the next iteration.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>It&#8217;s useful when we don&#8217;t want to write code right now but want to add functionality later.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#while loop pass statement\nprint(\"While loop Pass Statement\\n\")\nnum = 1\nwhile num &lt;= 10:\n    if num == 6:\n        pass\n    print(num)   \n    num += 1\n\nprint(\"\\nFor loop Pass Statement\\n\")\n#for loop pass statement\nfor num in range(1, 11):\n    if num == 6:\n        pass\n    print(num)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You can test the above example here!<\/strong>\u00a0\u27a1<a href=\"https:\/\/itsourcecode.com\/python-compiler\/\"><strong>Python Online Compiler<\/strong><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>While loop Pass Statement\n\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n\nFor loop Pass Statement\n\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-summary\"><strong>Summary<\/strong><\/h2>\n\n\n\n<p>To conclude, this article provides a comprehensive overview of loops in Python. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>It covers the concept of loops, their purpose in programming, and their ability to automate repetitive tasks. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The article explores three types of loops: <strong>for loops, while loops, and nested loops<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<div class=\"wp-block-columns tw-mb-0 tw-stretched-blocks tw-justify-center tw-gutter-no tw-cols-stack-sm tw-cols-card tw-cols-card-border tw-stretched-link is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-buttons tw-mb-0 tw-mt-0 is-content-justification-left is-nowrap is-layout-flex wp-container-core-buttons-is-layout-558b13e7 wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-base-3-background-color has-background wp-element-button\" href=\"https:\/\/itsourcecode.com\/python-tutorial\/python-decision-making-statements\/\" style=\"border-radius:0px\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\">\u2770\u2770<\/mark> <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\"><strong>Previous<\/strong><\/mark><\/a><\/div>\n<\/div>\n\n\n\n<p class=\"has-text-align-left tw-mt-0 tw-mb-0 tw-link-hover-underline\" style=\"font-style:normal;font-weight:100\">Python Decision Making<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column tw-mt-0 tw-mb-0 is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-buttons tw-mb-0 tw-mt-0 is-content-justification-right is-nowrap is-layout-flex wp-container-core-buttons-is-layout-5054138e wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-base-3-background-color has-background wp-element-button\" href=\"https:\/\/itsourcecode.com\/python-tutorial\/python-numbers-type-conversion-and-data-types-with-examples\/\" style=\"border-radius:0px\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-accent-color\"><strong>Next <\/strong>\u2771\u2771<\/mark><\/a><\/div>\n<\/div>\n\n\n\n<p class=\"has-text-align-right tw-mt-0 tw-mb-0 tw-link-hover-underline\" style=\"font-style:normal;font-weight:100\">Python Numbers<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>What are Loops in Python? The diagram below is the structure of a loop statement: Why do we use Loop in Python? The reason why we use loops in Python &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Loops in Python: Exploring For, While, and Nested Loops\" class=\"read-more button\" href=\"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/#more-66824\" aria-label=\"Read more about Loops in Python: Exploring For, While, and Nested Loops\">Read more<\/a><\/p>\n","protected":false},"author":1373,"featured_media":66665,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61036],"tags":[],"class_list":["post-66824","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorial","resize-featured-image"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Loops in Python: Exploring For, While, and Nested Loops<\/title>\n<meta name=\"description\" content=\"Loops in Python provide various types of loops like while loop, for loop, and nested loops in Python with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Loops in Python: Exploring For, While, and Nested Loops\" \/>\n<meta property=\"og:description\" content=\"Loops in Python provide various types of loops like while loop, for loop, and nested loops in Python with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Itsourcecode.com\" \/>\n<meta property=\"article:author\" content=\"www.facebook.com\/unguardable7\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-01T07:45:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-23T02:47:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Python-Loops.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1460\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prince Ly Cesar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@http:\/\/www.twitter.com\/unguardable0729\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prince Ly Cesar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/\"},\"author\":{\"name\":\"Prince Ly Cesar\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/8d6ff1c108160ddbd60ff17cbb9f626b\"},\"headline\":\"Loops in Python: Exploring For, While, and Nested Loops\",\"datePublished\":\"2022-07-01T07:45:32+00:00\",\"dateModified\":\"2023-11-23T02:47:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/\"},\"wordCount\":921,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Python-Loops.png\",\"articleSection\":[\"Python Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/\",\"name\":\"Loops in Python: Exploring For, While, and Nested Loops\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Python-Loops.png\",\"datePublished\":\"2022-07-01T07:45:32+00:00\",\"dateModified\":\"2023-11-23T02:47:42+00:00\",\"description\":\"Loops in Python provide various types of loops like while loop, for loop, and nested loops in Python with examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Python-Loops.png\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/Python-Loops.png\",\"width\":1460,\"height\":900,\"caption\":\"Loops in Python - For, While, and Nested Loops in Python Examples\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/python-tutorial\\\/loop-control-statements-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/itsourcecode.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Loops in Python: Exploring For, While, and Nested Loops\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/\",\"name\":\"Itsourcecode.com\",\"description\":\"Partner In Your Coding Journey!\",\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/itsourcecode.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\",\"name\":\"itsourcecode\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"width\":409,\"height\":409,\"caption\":\"itsourcecode\"},\"logo\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\"},\"description\":\"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!\",\"sameAs\":[\"https:\\\/\\\/itsourcecode.com\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/8d6ff1c108160ddbd60ff17cbb9f626b\",\"name\":\"Prince Ly Cesar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215\",\"caption\":\"Prince Ly Cesar\"},\"description\":\"Hi there! I'm Prince Ly Cesar a Student in Carlos Hilado Memorial State College - Binalbagan Campus and a Graphic Designer, Programmer &amp; Writer in IT SourceCode\",\"sameAs\":[\"https:\\\/\\\/activadorkeys.com\\\/\",\"www.facebook.com\\\/unguardable7\",\"http:\\\/\\\/www.instagram.com\\\/prnclycsr\\\/\",\"https:\\\/\\\/x.com\\\/http:\\\/\\\/www.twitter.com\\\/unguardable0729\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCF0BIqB5tpnCmwvYQCHucmw?view_as=subscriber\"],\"gender\":\"male\",\"knowsAbout\":[\"Graphic Designing\"],\"knowsLanguage\":[\"English\",\"Tagalog\"],\"jobTitle\":\"Graphic Designer\",\"worksFor\":\"IT SourceCode\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/author\\\/unguardable\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Loops in Python: Exploring For, While, and Nested Loops","description":"Loops in Python provide various types of loops like while loop, for loop, and nested loops in Python with examples.","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:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Loops in Python: Exploring For, While, and Nested Loops","og_description":"Loops in Python provide various types of loops like while loop, for loop, and nested loops in Python with examples.","og_url":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/","og_site_name":"Itsourcecode.com","article_author":"www.facebook.com\/unguardable7","article_published_time":"2022-07-01T07:45:32+00:00","article_modified_time":"2023-11-23T02:47:42+00:00","og_image":[{"width":1460,"height":900,"url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Python-Loops.png","type":"image\/png"}],"author":"Prince Ly Cesar","twitter_card":"summary_large_image","twitter_creator":"@http:\/\/www.twitter.com\/unguardable0729","twitter_misc":{"Written by":"Prince Ly Cesar","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/#article","isPartOf":{"@id":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/"},"author":{"name":"Prince Ly Cesar","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/8d6ff1c108160ddbd60ff17cbb9f626b"},"headline":"Loops in Python: Exploring For, While, and Nested Loops","datePublished":"2022-07-01T07:45:32+00:00","dateModified":"2023-11-23T02:47:42+00:00","mainEntityOfPage":{"@id":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/"},"wordCount":921,"commentCount":0,"publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"image":{"@id":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Python-Loops.png","articleSection":["Python Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/","url":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/","name":"Loops in Python: Exploring For, While, and Nested Loops","isPartOf":{"@id":"https:\/\/itsourcecode.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/#primaryimage"},"image":{"@id":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Python-Loops.png","datePublished":"2022-07-01T07:45:32+00:00","dateModified":"2023-11-23T02:47:42+00:00","description":"Loops in Python provide various types of loops like while loop, for loop, and nested loops in Python with examples.","breadcrumb":{"@id":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/#primaryimage","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Python-Loops.png","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/06\/Python-Loops.png","width":1460,"height":900,"caption":"Loops in Python - For, While, and Nested Loops in Python Examples"},{"@type":"BreadcrumbList","@id":"https:\/\/itsourcecode.com\/python-tutorial\/loop-control-statements-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/itsourcecode.com\/"},{"@type":"ListItem","position":2,"name":"Loops in Python: Exploring For, While, and Nested Loops"}]},{"@type":"WebSite","@id":"https:\/\/itsourcecode.com\/#website","url":"https:\/\/itsourcecode.com\/","name":"Itsourcecode.com","description":"Partner In Your Coding Journey!","publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itsourcecode.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc","name":"itsourcecode","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","width":409,"height":409,"caption":"itsourcecode"},"logo":{"@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg"},"description":"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!","sameAs":["https:\/\/itsourcecode.com\/"]},{"@type":"Person","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/8d6ff1c108160ddbd60ff17cbb9f626b","name":"Prince Ly Cesar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215","url":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215","caption":"Prince Ly Cesar"},"description":"Hi there! I'm Prince Ly Cesar a Student in Carlos Hilado Memorial State College - Binalbagan Campus and a Graphic Designer, Programmer &amp; Writer in IT SourceCode","sameAs":["https:\/\/activadorkeys.com\/","www.facebook.com\/unguardable7","http:\/\/www.instagram.com\/prnclycsr\/","https:\/\/x.com\/http:\/\/www.twitter.com\/unguardable0729","https:\/\/www.youtube.com\/channel\/UCF0BIqB5tpnCmwvYQCHucmw?view_as=subscriber"],"gender":"male","knowsAbout":["Graphic Designing"],"knowsLanguage":["English","Tagalog"],"jobTitle":"Graphic Designer","worksFor":"IT SourceCode","url":"https:\/\/itsourcecode.com\/author\/unguardable\/"}]}},"_links":{"self":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/66824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/users\/1373"}],"replies":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/comments?post=66824"}],"version-history":[{"count":20,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/66824\/revisions"}],"predecessor-version":[{"id":120644,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/66824\/revisions\/120644"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media\/66665"}],"wp:attachment":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media?parent=66824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/categories?post=66824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/tags?post=66824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}