{"id":23087,"date":"2021-12-09T17:23:45","date_gmt":"2021-12-09T11:53:45","guid":{"rendered":"https:\/\/tutorial.eyehunts.com\/?p=23087"},"modified":"2023-07-25T17:45:37","modified_gmt":"2023-07-25T12:15:37","slug":"while-loop-yes-or-no-python-example-code","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/","title":{"rendered":"While loop Yes or No Python | Example code"},"content":{"rendered":"\n<p>Use while true with <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-boolean-if-statement-example-codes\/\">if statement<\/a> and <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-break-statement-for-loop-while-for\/\">break statement<\/a> to create a While loop yes or no in Python. Simple if while condition equal to &#8220;N&#8221; then wait for the user input of Y before exiting.<\/p>\n\n\n\n<p>The basic syntax of a <code>while<\/code> loop in Python is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while condition:\r\n    # Code block to be executed while the condition is True\r\n    # ...\r\n    # ...\r<\/code><\/pre>\n\n\n\n<p>The <code>condition<\/code> is an expression that is evaluated before each iteration of the loop. If the condition is <code>True<\/code>, the code block inside the loop will be executed. After each iteration, the condition will be re-evaluated, and the loop will continue as long as the condition remains <code>True<\/code>.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example While loop yes or no in Python<\/strong><\/h2>\n\n\n\n<p>Simple example code using 2 while loops. If the user inputs the value &#8220;no&#8221; then break the loops.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while True:\n    # your code\n    cont = input(\"Another one? yes\/no &gt; \")\n\n    while cont.lower() not in (\"yes\", \"no\"):\n        cont = input(\"Another one? yes\/no &gt; \")\n\n    if cont == \"no\":\n        print(\"Break\")\n        break\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"362\" height=\"162\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/While-loop-yes-or-no-Python.jpg?resize=362%2C162&#038;ssl=1\" alt=\"While loop yes or no Python\" class=\"wp-image-23095\"\/><\/figure><\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>More examples<\/strong><\/p>\n\n\n\n<p>While looping in Python do you want to continue?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while True:\n    # some code here\n    if input('Do You Want To Continue? ') != 'y':\n        break<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<p>Do You Want To Continue? y<br>Do You Want To Continue? n<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>OR<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while input(\"Do You Want To Continue? &#91;y\/n]: \") == \"y\":\n    # do something\n    print(\"doing something\")<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: Do You Want To Continue? [y\/n]: n<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Long code with function<\/strong><\/h3>\n\n\n\n<p>Best to keep the function definition separate from the loop for clarity. Also, otherwise, it will be read in every loop wasting resources.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def yes_or_no(question):\n    reply = str(input(question + ' (y\/n): ')).lower().strip()\n    if reply&#91;0] == 'y':\n        return 1\n    elif reply&#91;0] == 'n':\n        return 0\n    else:\n        return yes_or_no(\"Please Enter (y\/n) \")\n\n\nprint(\"started\")\nwhile True:\n    # DRAW PLOT HERE;\n    print(\"See plot....\")\n    if yes_or_no('Do you like the plot'):\n        break\nprint(\"done\")\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: <\/p>\n\n\n\n<p>started<br>See plot\u2026.<br>Do you like the plot (y\/n): y<br>done<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Loop the question to allow for repeated incorrect input<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    answer = None \n    while answer not in (\"yes\", \"no\"): \n        answer = input(\"Enter yes or no: \") \n        if answer == \"yes\": \n             # Do this. \n        elif answer == \"no\": \n             # Do that. \n        else: \n        \tprint(\"Please enter yes or no.\") <\/code><\/pre>\n\n\n\n<p>Another example of using a <code>while<\/code> loop to ask the user for input and keep asking until they enter &#8220;yes&#8221; or &#8220;no&#8221;:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while True:\r\n    user_input = input(\"Enter 'yes' or 'no': \").lower()\r\n    if user_input == 'yes':\r\n        print(\"You entered 'yes'.\")\r\n        break\r\n    elif user_input == 'no':\r\n        print(\"You entered 'no'.\")\r\n        break\r\n    else:\r\n        print(\"Invalid input. Please try again.\")\r<\/code><\/pre>\n\n\n\n<p>In this example, the loop will continue indefinitely until the user enters either &#8220;yes&#8221; or &#8220;no.&#8221; The <code>lower()<\/code> method is used to convert the user&#8217;s input to lowercase, making it case-insensitive. When the user enters &#8220;yes&#8221; or &#8220;no,&#8221; the loop will exit using the <code>break<\/code> statement.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Comment if you have any doubts or suggestions on this Python while loop code.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> IDE:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>&nbsp;2021.3.3 (Community Edition)<\/p><p>Windows 10<\/p><p><strong>Python 3.10.1<\/strong><\/p><p>All<strong>&nbsp;Python Examples&nbsp;are in&nbsp;Python&nbsp;3<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Use while true with if statement and break statement to create a While loop yes or no in Python. Simple if while condition equal to &#8220;N&#8221; then wait for the user input of Y before exiting. The basic syntax of a while loop in Python is as follows: The condition is an expression that is&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">While loop Yes or No Python | Example code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[36,170],"post_series":[],"class_list":["post-23087","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-loops","tag-python-while"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>While loop Yes or No Python | Example code<\/title>\n<meta name=\"description\" content=\"Use while true with if statement and break statement to create While loop yes or no in Python. Simple if while condition equal to &quot;N&quot; then..\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"While loop Yes or No Python | Example code\" \/>\n<meta property=\"og:description\" content=\"Use while true with if statement and break statement to create While loop yes or no in Python. Simple if while condition equal to &quot;N&quot; then..\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-09T11:53:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-25T12:15:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/While-loop-yes-or-no-Python.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/\",\"name\":\"While loop Yes or No Python | Example code\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/While-loop-yes-or-no-Python.jpg\",\"datePublished\":\"2021-12-09T11:53:45+00:00\",\"dateModified\":\"2023-07-25T12:15:37+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"Use while true with if statement and break statement to create While loop yes or no in Python. Simple if while condition equal to \\\"N\\\" then..\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/While-loop-yes-or-no-Python.jpg?fit=362%2C162&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/While-loop-yes-or-no-Python.jpg?fit=362%2C162&ssl=1\",\"width\":362,\"height\":162},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"While loop Yes or No Python | Example code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"While loop Yes or No Python | Example code","description":"Use while true with if statement and break statement to create While loop yes or no in Python. Simple if while condition equal to \"N\" then..","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:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/","og_locale":"en_US","og_type":"article","og_title":"While loop Yes or No Python | Example code","og_description":"Use while true with if statement and break statement to create While loop yes or no in Python. Simple if while condition equal to \"N\" then..","og_url":"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/","og_site_name":"Tutorial","article_published_time":"2021-12-09T11:53:45+00:00","article_modified_time":"2023-07-25T12:15:37+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/While-loop-yes-or-no-Python.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/","url":"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/","name":"While loop Yes or No Python | Example code","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/While-loop-yes-or-no-Python.jpg","datePublished":"2021-12-09T11:53:45+00:00","dateModified":"2023-07-25T12:15:37+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"Use while true with if statement and break statement to create While loop yes or no in Python. Simple if while condition equal to \"N\" then..","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/While-loop-yes-or-no-Python.jpg?fit=362%2C162&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/While-loop-yes-or-no-Python.jpg?fit=362%2C162&ssl=1","width":362,"height":162},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/while-loop-yes-or-no-python-example-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"While loop Yes or No Python | Example code"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":18130,"url":"https:\/\/tutorial.eyehunts.com\/python\/a-while-loop-in-python-is-used-for-what-type-of-iteration\/","url_meta":{"origin":23087,"position":0},"title":"A while loop in Python is used for what type of iteration","author":"Rohit","date":"August 31, 2021","format":false,"excerpt":"Python, while loop is used for performing an indefinite iteration. That means repeatedly executing a section of code until a condition is met or no longer met. Where the number of times the loop will be executed, is not specified explicitly in advance. While(condition): { .... ...statement increment or decrement\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"A while loop in Python is used for what type of iteration","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/A-while-loop-in-Python-is-used-for-what-type-of-iteration.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":41719,"url":"https:\/\/tutorial.eyehunts.com\/python\/while-else-in-python\/","url_meta":{"origin":23087,"position":1},"title":"While else in Python","author":"Rohit","date":"August 16, 2023","format":false,"excerpt":"In Python, the while...else construct is a control structure that combines the while loop with an optional else block. The else block is executed when the loop's condition becomes false and the loop completes all its iterations without being prematurely terminated by a break statement. This can be useful for\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/08\/While-else-in-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":18954,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-stop-for-loop\/","url_meta":{"origin":23087,"position":2},"title":"Python stop for loop","author":"Rohit","date":"July 27, 2023","format":false,"excerpt":"In Python, you can stop a for loop prematurely using the break statement. The break statement is used to exit the loop immediately when a certain condition is met. Once the break statement is encountered, the loop terminates, and the program continues with the next statement after the loop. Here's\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/07\/Python-stop-for-loop.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":19350,"url":"https:\/\/tutorial.eyehunts.com\/python\/while-condition-python\/","url_meta":{"origin":23087,"position":3},"title":"while condition Python","author":"Rohit","date":"October 11, 2022","format":false,"excerpt":"Python while the condition is a loop and it is used to iterate over a block of code as long as the test expression (condition) is true. while(condition_statement){ #Loop body goes here } The condition_statement is a single condition or a set of multiple conditions that return a boolean value\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"while condition Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/10\/while-condition-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":18938,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-exit-for-loop-example-code\/","url_meta":{"origin":23087,"position":4},"title":"Python exit for loop | Example code","author":"Rohit","date":"December 6, 2021","format":false,"excerpt":"Use the break keyword with the if statement to exit for loop in Python. The break statement provides an opportunity to exit out of a loop when the condition is triggered. Here's an example of how you can use break to exit a for loop: for item in iterable: #\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python exit for loop","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/Python-exit-for-loop.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":33272,"url":"https:\/\/tutorial.eyehunts.com\/python\/continue-in-if-statement-python\/","url_meta":{"origin":23087,"position":5},"title":"Continue in if statement Python","author":"Rohit","date":"October 4, 2022","format":false,"excerpt":"Python Continue in if statement used to skip current iteration and instructs a loop to continue to the next iteration. Use continue statements within loops, usually after an if statement. Continue in the if statement Python A simple example code uses a continue statement in Python to skip over part\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/10\/Continue-in-if-statement-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/23087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=23087"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/23087\/revisions"}],"predecessor-version":[{"id":41285,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/23087\/revisions\/41285"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=23087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=23087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=23087"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=23087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}