{"id":9659,"date":"2020-03-26T16:14:04","date_gmt":"2020-03-26T10:44:04","guid":{"rendered":"http:\/\/ivyproschool.com\/blog\/?p=9659"},"modified":"2021-06-11T11:42:13","modified_gmt":"2021-06-11T06:12:13","slug":"python-loop","status":"publish","type":"post","link":"https:\/\/ivyproschool.com\/blog\/python-loop\/","title":{"rendered":"How Well Do You Know Loops in Python &#8211; Python Loop (GUIDE)"},"content":{"rendered":"<p><a href=\"https:\/\/ivyproschool.com\/blog\/python-loop\/\"><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9684 aligncenter\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-Cover-Image-Copy-300x139.png\" alt=\"Loops in Python\" width=\"300\" height=\"139\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-Cover-Image-Copy-300x139.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-Cover-Image-Copy-768x356.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-Cover-Image-Copy-1024x474.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-Cover-Image-Copy.png 1080w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"\"><br \/>\n<\/a><a href=\"\"><\/a><a href=\"\">In continuation of the previous post about <\/a><a href=\"https:\/\/ivyproschool.com\/blog\/2020\/03\/20\/top-5-python-data-types-that-you-should-know\/\">Python Data Types<\/a>, we proceed with the loop statements in Python. In this article, we are going to talk about the Python Loop &#8211; the For and While loops, their syntaxes with some examples, how we can use Else statements in these loops and how to create nested loops. We will also talk about loop control statements to exercise greater control over the loops.<\/p>\n<h2>For Loop &#8211;<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9681 aligncenter\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/for-300x139.png\" alt=\"For loop syntax\" width=\"300\" height=\"139\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/for-300x139.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/for-768x356.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/for-1024x474.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/for.png 1080w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>A <strong>for<\/strong> loop acts as an iterator in Python Loop. Objects that a for loop can iterate over include strings, lists, tuples, and built-in iterables for dictionaries, such as its keys or values. The loop goes through all items that are in a <em>sequence<\/em> or any other iterable item and executes the statements mentioned within the loop.<\/p>\n<p>Here&#8217;s the general format for a <strong>for<\/strong> loop in Python:<\/p>\n<h2>For Loop Syntax &#8211;<\/h2>\n<pre>for iterable_variable in sequence:\r\n    statements_to_execute<\/pre>\n<h3>For Loop Block Diagram &#8211;<\/h3>\n<p>When a for loop is encountered, the sequence is executed first if it is an expression. Then, the first item in the sequence is being assigned to the iterable_variable and the statements to execute is being performed. The loop progresses by picking up all the value in sequence one by one, executing the statement block until there is no more value to be assigned from the sequence to the iterable_variable.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9661 aligncenter\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/flow-chart-300x300.png\" alt=\"For Loop Flow Chart\" width=\"300\" height=\"300\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/flow-chart-300x300.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/flow-chart-150x150.png 150w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/flow-chart-768x768.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/flow-chart-1024x1024.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/flow-chart-100x100.png 100w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/flow-chart.png 1080w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<h3>For Loop examples:<\/h3>\n<h4>Example 1 &#8211; For Loop on a list of strings &#8211;<\/h4>\n<div>\n<div>\n<pre>school_names&nbsp;=&nbsp;['DPS',&nbsp;'DAV',&nbsp;'SDJBV',&nbsp;'SJV']\r\ni=0\r\nfor&nbsp;item&nbsp;in&nbsp;school_names:\r\n&nbsp; item&nbsp;=&nbsp;item&nbsp;+&nbsp;\"&nbsp;is&nbsp;a&nbsp;good&nbsp;school\"\r\n&nbsp; school_names[i]&nbsp;=&nbsp;item\r\n&nbsp; i = i + 1\r\nprint(school_names)<\/pre>\n<\/div>\n<\/div>\n<p>In the above code, we are working on a list of string elements which is the sequence. The item is our iterable_variable and the statement block concatenates &#8221; is a good school&#8221; to each item value and saves it as the elements of the list school_names.<\/p>\n<h4>Example 2 &#8211; For Loop on a list of numbers &#8211;<\/h4>\n<div>\n<pre>list1 = [1,2,3,4,5,6,7,8,9,10,11]\r\nfor i in range(len(list1)):\r\n&nbsp;&nbsp;&nbsp; if&nbsp;i%2==0:\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(list1[i])<\/pre>\n<\/div>\n<div>In the above code, we are printing all the elements from a list of numbers where its index position is even.<\/div>\n<h3>For Loop with Else Clause &#8211;<\/h3>\n<p>Else statements are usually used with an If statement which we find in all the programming languages. A very interesting feature of Python is that we can use an Else clause in association with the For loop.<\/p>\n<p>Let us first take a look at the traditional if-else conditional statement within a for loop. The code is provided below.<\/p>\n<div>\n<pre>numbers = [1,2,3,4,'q',3,2,4,2,3,2,1]\r\n\r\nfor&nbsp;num&nbsp;in&nbsp;numbers:\r\n&nbsp;&nbsp; if&nbsp;type(num)&nbsp;==&nbsp;str:\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print&nbsp;('the&nbsp;list&nbsp;contains&nbsp;a&nbsp;string')\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break\r\n   else:\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print&nbsp;('the&nbsp;list&nbsp;does&nbsp;not&nbsp;contain&nbsp;any&nbsp;string')<\/pre>\n<\/div>\n<pre>The output is : \r\n\r\nthe list does not contain any string \r\nthe list does not contain any string \r\nthe list does not contain any string \r\nthe list does not contain any string \r\nthe list contains a string<\/pre>\n<p>The code checks for the presence of a string value in the sequence list named numbers. For the first four elements which are numeric, the loop executes the else statement and prints the output. When the fifth element string value is found, the if statement becomes true, the consecutive print statement is executed and the break command causes the end of the loop. By observing the<\/p>\n<p>Now let us look at the Else clause after the For loop unique to Python. Here is the code.<\/p>\n<pre>numbers = [1,2,3,4,'q',3,2,4,2,3,2,1]\r\n\r\nfor num in numbers:\r\n&nbsp;&nbsp; if type(num) == str:\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print ('the list contains a string')\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break\r\n   else:\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print ('the list does not contain any string')\r\n\r\nThe output is: \r\n\r\nthe list contains a string<\/pre>\n<p class=\"output_text stream output-id-1\">The above code simply checks for a string element in the list. When this condition matches, it executes the print statement and breaks out of the loop. This also renders the Else clause useless. If the if condition is not met, only then the Else clause is executed.<\/p>\n<p><strong>Please Note &#8211;<\/strong> The else block just after for is executed only when the loop is NOT terminated by a break statement.<\/p>\n<h3>Single line For Loop &#8211;<\/h3>\n<div>\n<pre>[print(i) for i in range(5,100,5)]<\/pre>\n<h2>While Loop &#8211;<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9680 size-medium\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/while-loop-300x139.png\" alt=\"while loop syntax\" width=\"300\" height=\"139\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/while-loop-300x139.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/while-loop-768x356.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/while-loop-1024x474.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/while-loop.png 1080w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>The while loop executes the statements as long as the given condition for the loop is true. When the While condition turns false, the next command after the loop is executed.<\/p>\n<\/div>\n<h3>While Loop Syntax &#8211;<\/h3>\n<pre>while (condition): \r\n     conditional code\r\n<\/pre>\n<h3>Block Diagram for a While Loop-<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9673 aligncenter\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Chart2-300x300.png\" alt=\"Python While Loop Flow Chart\" width=\"300\" height=\"300\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Chart2-300x300.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Chart2-150x150.png 150w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Chart2-768x768.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Chart2-1024x1024.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Chart2-100x100.png 100w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Chart2.png 1080w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<h3>While Loop Example &#8211;<\/h3>\n<div>\n<pre>numbers&nbsp;=&nbsp;[1,2,3,4,'q',3,2,4,2,3,2,1]\r\ni&nbsp;=len(numbers)\r\nwhile(type(numbers[len(numbers)-i])&nbsp;!=&nbsp;str):\r\n&nbsp;&nbsp;&nbsp; print(numbers[len(numbers)-i])\r\n&nbsp;&nbsp;&nbsp; i-=1<\/pre>\n<\/div>\n<p>The While loop traces data types of each element in the list and prints the non-string values. The loop terminates at the first finding of a string.<\/p>\n<h3>While Loop with Else &#8211;<\/h3>\n<div>\n<pre>numbers&nbsp;=&nbsp;[1,2,3,4,'q',3,2,4,2,3,2,1]\r\ni&nbsp;=len(numbers)\r\nwhile(type(numbers[len(numbers)-i])&nbsp;!=&nbsp;str):\r\n&nbsp;&nbsp;&nbsp; print(numbers[len(numbers)-i])\r\n&nbsp;&nbsp;&nbsp; i-=1\r\nelse:\r\n&nbsp;&nbsp;print(\"Found&nbsp;a&nbsp;string&nbsp;at&nbsp;index\",&nbsp;len(numbers)-i)<\/pre>\n<\/div>\n<div>The code has an else statement that will execute only when the While loop condition becomes False. At index 4, the string data type element is found, the While condition turns False consequently executing the Else statement.<\/div>\n<h2>Nested Loops &#8211;<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9682 size-medium\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Nested-300x139.png\" alt=\"nested loop\" width=\"300\" height=\"139\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Nested-300x139.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Nested-768x356.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Nested-1024x474.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Nested.png 1080w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>When we structure a loop within a Python loop, we create a nested loop. Such a loop can comprise of a For loop within another For loop, a While loop within another While loop, or a mix of a For and a While loop.<\/p>\n<h4>Nested For Loop &#8211;<\/h4>\n<div>\n<pre>list1 = [1,2,3,4,5,6,7,8,'a',5]\r\nlist2 = [2,4,6,8,'a']\r\ncount = 0\r\nfor item1 in list1:\r\n&nbsp; for item2 in list2:\r\n &nbsp;&nbsp; if (item1==item2): \r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count = count + 1\r\nif (count &gt;1):\r\n&nbsp;&nbsp;&nbsp; print(\"We have\" , count , \"elements matching\")\r\nelse: \r\n &nbsp;print(\"No elements are matching\")<\/pre>\n<\/div>\n<p>The code matches elements between two lists, counts then umber of matching elements, and prints the result.<\/p>\n<h4>Nested While Loop &#8211;<\/h4>\n<div>\n<pre>i&nbsp;=&nbsp;[1,2,3,4,5,6,7,8]\r\nj&nbsp;=&nbsp;[10,11,12,13,14,15,16,17]\r\ny=0\r\nx=len(j)-1\r\nwhile&nbsp;x&gt;=0:\r\n&nbsp;&nbsp;&nbsp; while&nbsp;y&lt;len(j)-1:\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(i[x],&nbsp;\",\",&nbsp;j[y])\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y&nbsp;=&nbsp;y&nbsp;+&nbsp;1\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x&nbsp;=&nbsp;x&nbsp;-&nbsp;1<\/pre>\n<p>The code above simply prints elements of the first list in ascending order of its index while prints in reverse order for the second list.<\/p>\n<p>Can you think of a case where we construct a Nested loop with a For and a While together? Do let us know in the comment section.<\/p>\n<\/div>\n<h2>Loop Control Statements &#8211;<\/h2>\n<p>Loop control statements give us the power to change the execution from its normal flow or sequence in a way we want. Python supports the following control statements.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9685 aligncenter\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Control-loop-300x139.png\" alt=\"loop control statements\" width=\"300\" height=\"139\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Control-loop-300x139.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Control-loop-768x356.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Control-loop-1024x474.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Control-loop.png 1080w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>Continue Statement<\/strong> &#8211; It returns the control to the beginning of the loop.<\/p>\n<p><strong>Break Statement &#8211; <\/strong>It takes the control out of the loop<\/p>\n<p><strong>Pass Statement &#8211; <\/strong>We use pass statement to write empty loops.<\/p>\n<p>Let us see how we can solve the below problem by using the control statements.<\/p>\n<p><strong>Problem Statement<\/strong> &#8211;<\/p>\n<div>\n<div><em>Write a program that repeatedly prompts the user for an integer. If the integer is even, print the integer. If the integer is odd, don\u2019t print anything.&nbsp;Exit the program if the user enters the integer 99.<\/em><\/div>\n<\/div>\n<p><strong>Solution code &#8211;<\/strong><\/p>\n<div>\n<pre>while True:\r\n\r\n&nbsp;&nbsp;try:\r\n&nbsp;&nbsp;&nbsp; x&nbsp;=&nbsp;int(input(\"enter&nbsp;a&nbsp;number&nbsp;-&nbsp;\"))\r\n&nbsp;&nbsp;&nbsp; if(x%2==0):\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(\"The&nbsp;integer\",x,\"is&nbsp;even\")\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue\r\n&nbsp;&nbsp;&nbsp; elif(x%2!=0):\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass\r\n&nbsp;&nbsp;&nbsp; elif(x==99):\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break\r\n\r\n &nbsp;except:\r\n&nbsp;&nbsp;&nbsp; print&nbsp;(\"Not&nbsp;an&nbsp;integer\")\r\n &nbsp;&nbsp; continue\r\n\r\n<\/pre>\n<h2>Conclusion &#8211;<\/h2>\n<p>In this article, we have given a detailed explanation of all the Python Loops &#8211; For, While, and Nested loops with interesting yet simple examples to get a clear understanding. I hope you enjoyed reading and learn by practicing. Stay tuned for more such tutorials. Happy Learning!!<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In continuation of the previous post about Python Data Types, we proceed with the loop statements in Python. In this article, we are going to talk about the Python Loop &#8211; the For and While loops, their syntaxes with some examples, how we can use Else statements in these loops and how to create nested loops. We will also talk about loop control statements to exercise greater control over the loops. For Loop &#8211; A for loop acts as an iterator in Python Loop. Objects that a for loop can iterate over include strings, lists, tuples, and built-in iterables for dictionaries, such as its keys or values. The loop goes through all items that are in a sequence or any other iterable item and executes the statements mentioned within the loop. Here&#8217;s the general format for a for loop in Python: For Loop Syntax &#8211; for iterable_variable in sequence: statements_to_execute For Loop Block Diagram &#8211; When a for loop is encountered, the sequence is executed first if it is an expression. Then, the first item in the sequence is being assigned to the iterable_variable and the statements to execute is being performed. The loop progresses by picking up all the [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":9684,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[851,5,881,715,552],"tags":[16,76,810,230,294,467,811,110,809,813,140,716,812],"class_list":["post-9659","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-business-analytics","category-data-analytics","category-data-science","category-machine-learning-ai","category-technology","tag-analytics-career","tag-business-analytics","tag-control-statements","tag-data-analytics","tag-data-mining","tag-data-science","tag-for","tag-ivyproschool","tag-loops","tag-nested","tag-predictive-analytics","tag-python","tag-while"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How Well Do You Know Loops in Python? | Python Loop EXPLAINED<\/title>\n<meta name=\"description\" content=\"In this article we are going to understand the For, While and Nested Loops including Loop Control Statements. Learn about Python Loop from Ivy Pro School.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ivyproschool.com\/blog\/python-loop\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How Well Do You Know Loops in Python? | Python Loop EXPLAINED\" \/>\n<meta property=\"og:description\" content=\"In this article we are going to understand the For, While and Nested Loops including Loop Control Statements. Learn about Python Loop from Ivy Pro School.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ivyproschool.com\/blog\/python-loop\/\" \/>\n<meta property=\"og:site_name\" content=\"R vs Python: Which Analytics Tool Should You Choose for Data Science?\" \/>\n<meta property=\"article:author\" content=\"https:\/\/facebook.com\/ivyproschool\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-26T10:44:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-11T06:12:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-Cover-Image-Copy.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1080\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ivy Professional School\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ivyproschool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ivy Professional School\" \/>\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:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/\"},\"author\":{\"name\":\"Ivy Professional School\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/31fdab8559dd3db99173764bfb60215d\"},\"headline\":\"How Well Do You Know Loops in Python &#8211; Python Loop (GUIDE)\",\"datePublished\":\"2020-03-26T10:44:04+00:00\",\"dateModified\":\"2021-06-11T06:12:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/\"},\"wordCount\":965,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Blog-Cover-Image-Copy.png\",\"keywords\":[\"Analytics Career\",\"business analytics\",\"Control Statements\",\"data analytics\",\"data mining\",\"data science\",\"For\",\"ivyproschool\",\"Loops\",\"Nested\",\"predictive analytics\",\"python\",\"While\"],\"articleSection\":[\"Business Analytics\",\"Data Analytics\",\"Data Science\",\"Machine Learning &amp; AI\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/\",\"name\":\"How Well Do You Know Loops in Python? | Python Loop EXPLAINED\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Blog-Cover-Image-Copy.png\",\"datePublished\":\"2020-03-26T10:44:04+00:00\",\"dateModified\":\"2021-06-11T06:12:13+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/31fdab8559dd3db99173764bfb60215d\"},\"description\":\"In this article we are going to understand the For, While and Nested Loops including Loop Control Statements. Learn about Python Loop from Ivy Pro School.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/#primaryimage\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Blog-Cover-Image-Copy.png\",\"contentUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Blog-Cover-Image-Copy.png\",\"width\":1080,\"height\":500,\"caption\":\"Loops in Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/python-loop\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How Well Do You Know Loops in Python &#8211; Python Loop (GUIDE)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/\",\"name\":\"Ivy Professional School | Official Blog\",\"description\":\"Confused between R and Python for your data science journey? Discover the key differences in data visualization, handling capabilities, speed, and ease of learning.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/31fdab8559dd3db99173764bfb60215d\",\"name\":\"Ivy Professional School\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g\",\"caption\":\"Ivy Professional School\"},\"sameAs\":[\"http:\\\/\\\/www.ivyproschool.com\",\"https:\\\/\\\/facebook.com\\\/ivyproschool\",\"https:\\\/\\\/instagram.com\\\/ivyproschool\",\"https:\\\/\\\/x.com\\\/ivyproschool\",\"https:\\\/\\\/youtube.com\\\/ivyproschool\"],\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/author\\\/prateek\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How Well Do You Know Loops in Python? | Python Loop EXPLAINED","description":"In this article we are going to understand the For, While and Nested Loops including Loop Control Statements. Learn about Python Loop from Ivy Pro School.","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:\/\/ivyproschool.com\/blog\/python-loop\/","og_locale":"en_US","og_type":"article","og_title":"How Well Do You Know Loops in Python? | Python Loop EXPLAINED","og_description":"In this article we are going to understand the For, While and Nested Loops including Loop Control Statements. Learn about Python Loop from Ivy Pro School.","og_url":"https:\/\/ivyproschool.com\/blog\/python-loop\/","og_site_name":"R vs Python: Which Analytics Tool Should You Choose for Data Science?","article_author":"https:\/\/facebook.com\/ivyproschool","article_published_time":"2020-03-26T10:44:04+00:00","article_modified_time":"2021-06-11T06:12:13+00:00","og_image":[{"width":1080,"height":500,"url":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-Cover-Image-Copy.png","type":"image\/png"}],"author":"Ivy Professional School","twitter_card":"summary_large_image","twitter_creator":"@ivyproschool","twitter_misc":{"Written by":"Ivy Professional School","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ivyproschool.com\/blog\/python-loop\/#article","isPartOf":{"@id":"https:\/\/ivyproschool.com\/blog\/python-loop\/"},"author":{"name":"Ivy Professional School","@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/31fdab8559dd3db99173764bfb60215d"},"headline":"How Well Do You Know Loops in Python &#8211; Python Loop (GUIDE)","datePublished":"2020-03-26T10:44:04+00:00","dateModified":"2021-06-11T06:12:13+00:00","mainEntityOfPage":{"@id":"https:\/\/ivyproschool.com\/blog\/python-loop\/"},"wordCount":965,"commentCount":0,"image":{"@id":"https:\/\/ivyproschool.com\/blog\/python-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-Cover-Image-Copy.png","keywords":["Analytics Career","business analytics","Control Statements","data analytics","data mining","data science","For","ivyproschool","Loops","Nested","predictive analytics","python","While"],"articleSection":["Business Analytics","Data Analytics","Data Science","Machine Learning &amp; AI","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ivyproschool.com\/blog\/python-loop\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ivyproschool.com\/blog\/python-loop\/","url":"https:\/\/ivyproschool.com\/blog\/python-loop\/","name":"How Well Do You Know Loops in Python? | Python Loop EXPLAINED","isPartOf":{"@id":"https:\/\/ivyproschool.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ivyproschool.com\/blog\/python-loop\/#primaryimage"},"image":{"@id":"https:\/\/ivyproschool.com\/blog\/python-loop\/#primaryimage"},"thumbnailUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-Cover-Image-Copy.png","datePublished":"2020-03-26T10:44:04+00:00","dateModified":"2021-06-11T06:12:13+00:00","author":{"@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/31fdab8559dd3db99173764bfb60215d"},"description":"In this article we are going to understand the For, While and Nested Loops including Loop Control Statements. Learn about Python Loop from Ivy Pro School.","breadcrumb":{"@id":"https:\/\/ivyproschool.com\/blog\/python-loop\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ivyproschool.com\/blog\/python-loop\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ivyproschool.com\/blog\/python-loop\/#primaryimage","url":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-Cover-Image-Copy.png","contentUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-Cover-Image-Copy.png","width":1080,"height":500,"caption":"Loops in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/ivyproschool.com\/blog\/python-loop\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ivyproschool.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How Well Do You Know Loops in Python &#8211; Python Loop (GUIDE)"}]},{"@type":"WebSite","@id":"https:\/\/ivyproschool.com\/blog\/#website","url":"https:\/\/ivyproschool.com\/blog\/","name":"Ivy Professional School | Official Blog","description":"Confused between R and Python for your data science journey? Discover the key differences in data visualization, handling capabilities, speed, and ease of learning.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ivyproschool.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/31fdab8559dd3db99173764bfb60215d","name":"Ivy Professional School","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g","caption":"Ivy Professional School"},"sameAs":["http:\/\/www.ivyproschool.com","https:\/\/facebook.com\/ivyproschool","https:\/\/instagram.com\/ivyproschool","https:\/\/x.com\/ivyproschool","https:\/\/youtube.com\/ivyproschool"],"url":"https:\/\/ivyproschool.com\/blog\/author\/prateek\/"}]}},"_links":{"self":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/comments?post=9659"}],"version-history":[{"count":1,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9659\/revisions"}],"predecessor-version":[{"id":10574,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9659\/revisions\/10574"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/media\/9684"}],"wp:attachment":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/media?parent=9659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/categories?post=9659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/tags?post=9659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}