{"id":12192,"date":"2020-12-14T11:43:44","date_gmt":"2020-12-14T19:43:44","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12192"},"modified":"2023-12-01T04:05:54","modified_gmt":"2023-12-01T12:05:54","slug":"do-while-python","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/do-while-python\/","title":{"rendered":"Do While Python: A Step-By-Step Guide"},"content":{"rendered":"\n<p><em>The do while Python loop executes a block of code repeatedly while a boolean condition remains true. The Python syntax for while loops is while[condition]. A &#8220;do while&#8221; loop is called a while loop in Python.<\/em><\/p>\n\n\n\n<p>Most programming languages include a useful feature to help you automate repetitive tasks. This feature is referred to as <em>loops<\/em>.<\/p>\n\n\n\n<p>For example, say you want to write a program that prints out individually the names of every student in a list. You may want to use a loop to print out each name rather than separate print() statements.<\/p>\n\n\n\n<p>In this tutorial, we are going to break down the <em>do while loop<\/em> (which is officially called a <em>while loop<\/em>) in Python. A while loop can be used to repeat a certain block of code based on the result of a boolean condition. The code in the while block will be run as long as the statement in the while loop is True.<\/p>\n\n\n\n<p>We\u2019ll also run through a couple of examples of how to use a <em>do while<\/em> loop in Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">For Loop Refresher<\/h2>\n\n\n\n<p>Loops are useful in a vast number of different situations when you\u2019re programming. As a result, Python has two built-in functions that allow you to create loops: for and while.<\/p>\n\n\n\n<p>Here\u2019s an example of a <a href=\"https:\/\/careerkarma.com\/blog\/python-for-loop\/\">Python for loop<\/a> in action that iterates through a range of values:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>for i in range(0, 3):\n\tprint(i)<\/pre><\/div>\n\n\n\n<p>We use a <a href=\"https:\/\/careerkarma.com\/blog\/python-range\/\">Python range() statement<\/a> to create a list of values over which our while loop can iterate. Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>0\n1\n2<\/pre><\/div>\n\n\n\n<p>The for loop sets <em>i<\/em> as the iterator, which keeps track of how many times the loop has been executed. The loop runs three times, or once for each item in the range of 1 and <em>3<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Do While Python<\/h2>\n\n\n\n<p>Python do while loops run a block of code while a statement evaluates to true. The loop stops running when a statement evaluates to false. A  condition evaluates to False at some point otherwise your loop will execute forever.<\/p>\n\n\n\n<p>Here\u2019s the syntax for creating a while loop in Python:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>while [our condition is True]:\n\t[run code]<\/pre><\/div>\n\n\n\n<p>We use the &#8220;while&#8221; keyword to denote our while loop.<\/p>\n\n\n\n<p>Our loop will continue to run until the condition being evaluated is equal to false. In many programming languages, this is called a <em>do while<\/em> loop, but in Python we simply refer to it as a <em>while loop<\/em>.<\/p>\n\n\n\n<p>Once our condition evaluates to False, the loop is terminated. A loop that does not have a condition that evaluates to False is called an infinite loop. This type of loop is called an infinite loop because it does not run for a specified number of times. The loop keeps going.<\/p>\n\n\n\n<p>Each time the while loop runs, our code checks the condition in the loop. If the condition is met, the loop is run.<\/p>\n\n\n\n<p>This is slightly different to a &#8220;do while&#8221; loop with which you may be familiar in other programming languages. A &#8220;do while&#8221; loop executes a loop and then evaluates a condition. &#8220;do while&#8221; loops do not exist in Python so we&#8217;ll focus on regular while loops.<\/p>\n\n\n\n<p>Let\u2019s use an example to illustrate how a while loop works in Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python Do While Example<\/h2>\n\n\n\n<p>We are going to create a program that asks a user to guess the magic number. Our program should continue to run until the user guesses correctly.<\/p>\n\n\n\n<p>If the user guesses the number incorrectly, the loop will keep going, and if the user guesses the correct number, the loop will stop.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Write a Basic While Loop<\/h3>\n\n\n\n<p>Here\u2019s the code for our example <em>while<\/em> loop program that runs whlile a condition is True:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>user_guess = 0\nmagic_number = 5\n\nwhile user_guess != magic_number:\n\tprint('What is the magic number?')\n\tuser_guess = int(input())\n\nprint('You have correctly guessed the magic number!')<\/pre><\/div>\n\n\n\n<p>On the first two lines of our code, we declare two <a href=\"https:\/\/careerkarma.com\/blog\/python-variables\/\">Python variables<\/a>. The <em>user_guess<\/em> variable will be used to store the number our user inputs into the program. The <em>magic_number<\/em> variable stores the number the user is attempting to guess.<\/p>\n\n\n\n<p>On the next line, we declare our <em>while<\/em> loop. This loop checks if the variable <em>user_guess<\/em> is not equal to <em>magic_number<\/em>, and if these values are not the same, the loop will run. In other words, if our user has not guessed the correct magic number, the while loop will execute. The code inside our while loop is called the body of the loop.<\/p>\n\n\n\n<p>We print the statement &#8220;<em>What is the magic number?&#8221;<\/em> We then use the <a href=\"https:\/\/careerkarma.com\/blog\/python-input\/\">Python <em>input()<\/em> function<\/a> to request a guess from the user.<\/p>\n\n\n\n<p>Our program will check to see if the <em>while<\/em> condition is still True when the user presses the enter key. When the condition becomes False, our loop stops executing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the Program<\/h3>\n\n\n\n<p>Here\u2019s what happens if we guess the wrong number:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>What is the magic number?\n1\nWhat is the magic number?\n2\nWhat is the magic number?\n3\nWhat is the magic number?<\/pre><\/div>\n\n\n\n<p>If we guess the wrong number, the program executes the <em>while<\/em> loop again. Our loop keep running until we enter the right number. At this point, our loop body will stop running and our program will move on.<\/p>\n\n\n\n<p>Here\u2019s what happens if we guess the correct number:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>What is the magic number?\n5\nYou have correctly guessed the magic number!<\/pre><\/div>\n\n\n\n<p>After we guessed the correct number, <em>user_guess<\/em> was equal to <em>magic_number<\/em> and so our while loop stopped running. Then, our program printed out the message stating that we had correctly guessed the magic number.<\/p>\n\n\n\n<p>Remember that when you\u2019re working with <em>input()<\/em>, you may need to convert the values that you are receiving from a user. In our case, we had to use <em>int(input())<\/em> because we were gathering numbers from a user. If we wanted our values to be strings, though, we would not have to convert our values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Improving the Do While Python Loop Example<\/h2>\n\n\n\n<p>Now that we know the basics of while loops in Python, we can start to explore more advanced loops. We are going to create another guessing game. But, this time we are going to include a few additional features to make it more functional for users.<\/p>\n\n\n\n<p>The specifications for our program are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The magic number must be automatically generated.<\/li><li>The user should only get three attempts to guess the magic number.<\/li><li>If the user guesses the correct number, they should receive a message.<\/li><\/ul>\n\n\n\n<p>Let\u2019s build our program!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Writing the Program<\/h3>\n\n\n\n<p>Firstly, we are going to import the <em>random<\/em> module using <em>import<\/em>, which allows us to generate random numbers. Then, we are going to create a variable that stores a randomly-generated number. We can do so using this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import random\n\nmagic_number = random.randint(1,20)<\/pre><\/div>\n\n\n\n<p>In our code below, we are going to define a while loop, like we did above, which receives our user\u2019s guess. But in this example, we are going to use <em>while<\/em> to check how many times a user has guessed the number. If that number is more than 4, the loop will not run. Here\u2019s our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import random\n\nmagic_number = random.randint(1,20)\n\nattempts = 0\n\nwhile attempts &lt; 5:\n\tprint(&quot;Guess a number between 1 and 20:&quot;)\n\n\tguess = int(input())\n\n\tattempts = attempts + 1\n\n\tif guess == magic_number:\n\t\tbreak\n\nprint(&quot;You have guessed the magic number!&quot;)<\/pre><\/div>\n\n\n\n<p>Our <em>while<\/em> loop checks if a user has attempted to guess the loop fewer than four times. If the user has used up fewer than four guesses, the code within our loop will run. Then, the message &#8220;<em>Guess a number between 1 and 20:&#8221;<\/em> will be printed to the console. The user will be prompted to guess a number.<\/p>\n\n\n\n<p>We increase the number of attempts a user has had by 1. This allows us to keep track of how many guesses a user has had.<\/p>\n\n\n\n<p>We then check to see if the user\u2019s guess is equal to the <em>magic_number<\/em> that our program generated earlier. If <em>guess<\/em> is equal to <em>magic_number<\/em>, our while loop will stop because we have used a <em>break<\/em> statement.<\/p>\n\n\n\n<p>You can learn more about the break keyword in our <a href=\"https:\/\/careerkarma.com\/blog\/python-break-and-continue\/\">Python break statement guide<\/a>.<\/p>\n\n\n\n<p>Once our <em>break<\/em> statement is executed, our loop will stop. The statement &#8220;<em>You have guessed the magic number!<\/em>&#8221; will be printed to the console.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the Program<\/h3>\n\n\n\n<p>Let\u2019s test our code to see if it works. When we guess a number incorrectly, our loop runs again like this:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Guess a number between 1 and 20:\n1\nGuess a number between 1 and 20:\n2\nGuess a number between 1 and 20:\n3<\/pre><\/div>\n\n\n\n<p>But when we guess the number correctly, our program returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Guess a number between 1 and 20:\n5\nYou have guessed the magic number!<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Python while loops (which are often called <em>do while<\/em> loops in other languages) execute a block of code while a statement evaluates to true. The syntax for a while loop is: while [your condition]. A while loop should eventually evaluate to false otherwise it will not stop.<\/p>\n\n\n\n<p>For example, you may want to use a while loop to check if a user\u2019s password is correct on a login form.<\/p>\n\n\n\n<p>Are you up for a challenge? Write a while loop that prints out every value in this list to the console:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>names = [&quot;Mark&quot;, &quot;Luke&quot;, &quot;Mary&quot;, &quot;Louise&quot;]<\/pre><\/div>\n\n\n\n<p>Then, write a while loop that prints out each name in the console whose length is over four characters. You may want to use the <a href=\"https:\/\/careerkarma.com\/blog\/python-len\/\">Python len() statement<\/a> to help you out.<\/p>\n\n\n\n<p>The final output should be:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Louise<\/pre><\/div>\n\n\n\n<p>Now you\u2019re ready to start writing while loops like a pro in Python!<\/p>\n\n\n\n<p>For advice on top Python learning resources, courses, and books, check out our <a href=\"https:\/\/careerkarma.com\/blog\/how-to-learn-python\/\">How to Learn Python guide<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"The do while Python loop executes a block of code repeatedly while a boolean condition remains true. The Python syntax for while loops is while[condition]. A \"do while\" loop is called a while loop in Python. Most programming languages include a useful feature to help you automate repetitive tasks. This feature is referred to as&hellip;","protected":false},"author":240,"featured_media":12193,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-12192","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Do While Python: A Step-By-Step Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"Python while loops allow programmers to run a certain block of code while a specified condition evaluates to true. Learn about how while loops work, and how you can use them in Python, on Career Karma.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/do-while-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Do While Python: A Step-By-Step Guide\" \/>\n<meta property=\"og:description\" content=\"Python while loops allow programmers to run a certain block of code while a specified condition evaluates to true. Learn about how while loops work, and how you can use them in Python, on Career Karma.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/do-while-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-14T19:43:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T12:05:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/Python-.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"668\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Do While Python: A Step-By-Step Guide\",\"datePublished\":\"2020-12-14T19:43:44+00:00\",\"dateModified\":\"2023-12-01T12:05:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/\"},\"wordCount\":1473,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Python-.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/\",\"name\":\"Do While Python: A Step-By-Step Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Python-.jpg\",\"datePublished\":\"2020-12-14T19:43:44+00:00\",\"dateModified\":\"2023-12-01T12:05:54+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"Python while loops allow programmers to run a certain block of code while a specified condition evaluates to true. Learn about how while loops work, and how you can use them in Python, on Career Karma.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Python-.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Python-.jpg\",\"width\":1000,\"height\":668},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/do-while-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Do While Python: A Step-By-Step Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Do While Python: A Step-By-Step Guide | Career Karma","description":"Python while loops allow programmers to run a certain block of code while a specified condition evaluates to true. Learn about how while loops work, and how you can use them in Python, on Career Karma.","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:\/\/careerkarma.com\/blog\/do-while-python\/","og_locale":"en_US","og_type":"article","og_title":"Do While Python: A Step-By-Step Guide","og_description":"Python while loops allow programmers to run a certain block of code while a specified condition evaluates to true. Learn about how while loops work, and how you can use them in Python, on Career Karma.","og_url":"https:\/\/careerkarma.com\/blog\/do-while-python\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-12-14T19:43:44+00:00","article_modified_time":"2023-12-01T12:05:54+00:00","og_image":[{"width":1000,"height":668,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/Python-.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/do-while-python\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/do-while-python\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Do While Python: A Step-By-Step Guide","datePublished":"2020-12-14T19:43:44+00:00","dateModified":"2023-12-01T12:05:54+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/do-while-python\/"},"wordCount":1473,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/do-while-python\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/Python-.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/do-while-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/do-while-python\/","url":"https:\/\/careerkarma.com\/blog\/do-while-python\/","name":"Do While Python: A Step-By-Step Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/do-while-python\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/do-while-python\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/Python-.jpg","datePublished":"2020-12-14T19:43:44+00:00","dateModified":"2023-12-01T12:05:54+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"Python while loops allow programmers to run a certain block of code while a specified condition evaluates to true. Learn about how while loops work, and how you can use them in Python, on Career Karma.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/do-while-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/do-while-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/do-while-python\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/Python-.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/Python-.jpg","width":1000,"height":668},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/do-while-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Do While Python: A Step-By-Step Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12192"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12192\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/12193"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}