{"id":7236,"date":"2024-03-19T06:46:05","date_gmt":"2024-03-19T06:46:05","guid":{"rendered":"https:\/\/www.skillvertex.com\/blog\/?p=7236"},"modified":"2024-03-19T06:46:05","modified_gmt":"2024-03-19T06:46:05","slug":"python-while-loop","status":"publish","type":"post","link":"https:\/\/www.skillvertex.com\/blog\/python-while-loop\/","title":{"rendered":"Python while Loop"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\" id=\"rank-math-toc\"><p>Table of Contents<\/p><nav><ul><li ><a href=\"#what-are-the-types-of-python-loops\">What are the types of Python Loops?<\/a><\/li><li ><a href=\"#what-is-while-loop\">What is while Loop?<\/a><\/li><li ><a href=\"#what-is-the-break-statement\">What is the break statement?<\/a><\/li><li ><a href=\"#what-is-the-continue-statement\">What is the Continue Statement?<\/a><\/li><li ><a href=\"#what-is-the-else-statement\">What is the else statement?<\/a><\/li><li ><a href=\"#conclusion\">Conclusion<\/a><\/li><li ><a href=\"#python-while-loop-fa-qs\">Python while Loop- FAQs<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<p>The while Loop statement in<a href=\"https:\/\/www.skillvertex.com\/blog\/python-tutorial\/\" data-type=\"post\" data-id=\"6852\"> Python Programming language <\/a>will repeatedly run the target statement until the<a href=\"https:\/\/www.skillvertex.com\/blog\/python-booleans\/\" data-type=\"post\" data-id=\"7030\"> boolean expression <\/a>comes true. Read this article to learn about Python while Loop.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-are-the-types-of-python-loops\">What are the types of Python Loops?<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.skillvertex.com\/blog\/how-to-take-input-in-python\/\" data-type=\"post\" data-id=\"7014\">Python<\/a> consists of two primitive loop <a href=\"https:\/\/www.skillvertex.com\/blog\/in-sql-which-of-the-following-is-not-a-data-manipulation-language-commands\/\" data-type=\"post\" data-id=\"2308\">commands<\/a><\/p>\n\n\n\n<p>a.<strong> While loops<\/strong><\/p>\n\n\n\n<p>b. <strong>For loops<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-while-loop\">What is while Loop?<\/h2>\n\n\n\n<p>The <strong><a href=\"https:\/\/www.skillvertex.com\/blog\/for-versus-while\/\" data-type=\"post\" data-id=\"2019\">while Loop<\/a><\/strong> will run the set of <a href=\"https:\/\/www.skillvertex.com\/blog\/python-if-else-statement\/\" data-type=\"post\" data-id=\"7153\">statements<\/a> until the<a href=\"https:\/\/www.skillvertex.com\/blog\/conditional-or-ternary-operator-in-c\/\" data-type=\"post\" data-id=\"2262\"> condition<\/a> comes true. <\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Example of a while loop\ncount = 1\n\nwhile count &lt;= 5:\n    print(count)\n    count += 1\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n2\n3\n4\n5\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-the-break-statement\">What is the break statement?<\/h2>\n\n\n\n<p>The<strong> <a href=\"https:\/\/www.skillvertex.com\/blog\/break-statement-in-c\/\" data-type=\"post\" data-id=\"2014\">break statement <\/a><\/strong>means that it will terminate the<a href=\"https:\/\/www.skillvertex.com\/blog\/c-for-loop\/\" data-type=\"post\" data-id=\"2045\"> loop<\/a> even though the condition comes true.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n2\n3\n4\n5\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n2\n3\n4\n5\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-the-continue-statement\">What is the Continue Statement?<\/h2>\n\n\n\n<p>The <strong><a href=\"https:\/\/www.skillvertex.com\/blog\/continue-statement-in-c\/\" data-type=\"post\" data-id=\"2295\">continue statement<\/a> <\/strong>indicates that it is possible to stop the current iteration and will continue with the next.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Example of using the continue statement in a while loop\ncount = 0\n\nwhile count &lt; 5:\n    count += 1\n\n    if count == 3:\n        # Skip printing when count is 3\n        continue\n\n    print(count)\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n2\n4\n5\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-the-else-statement\">What is the else statement?<\/h2>\n\n\n\n<p>The <strong><a href=\"https:\/\/www.skillvertex.com\/blog\/python-if-else-statement\/\" data-type=\"post\" data-id=\"7153\">else statement<\/a> <\/strong>will<a href=\"https:\/\/www.skillvertex.com\/blog\/c-library-math-h-functions\/\" data-type=\"post\" data-id=\"2596\"> function<\/a> to run the<a href=\"https:\/\/www.skillvertex.com\/blog\/blockchain-developer-salary\/\" data-type=\"post\" data-id=\"1120\"> block of code <\/a>even though the condition is false.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Example of using the else statement in a while loop\ncount = 1\n\nwhile count &lt;= 5:\n    print(count)\n    count += 1\nelse:\n    print(\"Loop completed successfully.\")\n<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n2\n3\n4\n5\nLoop completed successfully.\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>To conclude, this article will summarize the  Python while loops. Students can improve their knowledge and skills after learning this. Two types of loops are included in this along with the example.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"python-while-loop-fa-qs\">Python while Loop- FAQs<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1708085025628\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q1. What is the use of a while loop?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. While loop functions to repeat the specific block of code an infinite number of times until the condition comes true.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1708085032857\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q2. How does a while loop start?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. The while loop will begin by checking the condition. It will check if the condition comes true, then the code block will run the program.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1708085042114\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q3. Which loop never ends?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans.  An infinite Loop is a loop that will<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>The while Loop statement in Python Programming language will repeatedly run the target statement until the boolean expression comes true. Read this article to learn about Python while Loop. What are the types of Python Loops? Python consists of two primitive loop commands a. While loops b. For loops What is while Loop? The while &#8230; <a title=\"Python while Loop\" class=\"read-more\" href=\"https:\/\/www.skillvertex.com\/blog\/python-while-loop\/\" aria-label=\"More on Python while Loop\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":7237,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[864],"tags":[72,57,866,920],"class_list":["post-7236","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorial","tag-programming","tag-python","tag-python-tutorial","tag-python-while-loop","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"_links":{"self":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/7236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/comments?post=7236"}],"version-history":[{"count":6,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/7236\/revisions"}],"predecessor-version":[{"id":8268,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/7236\/revisions\/8268"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media\/7237"}],"wp:attachment":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media?parent=7236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/categories?post=7236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/tags?post=7236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}