{"id":130083,"date":"2022-04-13T15:00:11","date_gmt":"2022-04-13T19:00:11","guid":{"rendered":"https:\/\/brainstation.io\/?post_type=codex-reference&#038;p=130083"},"modified":"2025-02-04T14:41:39","modified_gmt":"2025-02-04T19:41:39","slug":"while-loop","status":"publish","type":"codex-reference","link":"https:\/\/brainstation.io\/learn\/python\/while-loop","title":{"rendered":"While Loop"},"content":{"rendered":"\n<header class=\"wp-block-bstn-blocks-hero-simple bstn-blocks-hero-simple\"><div class=\"bstn-blocks-hero-simple__full-width-wrapper bstn-blocks-hero-simple__full-width-wrapper--main bstn-blocks-hero-simple__full-width-wrapper--bg-flair\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewbox=\"0 0 1140 621\" fill=\"none\" class=\"bstn-blocks-hero-simple__bg-flair--rich\"><g opacity=\"0.55\"><path stroke=\"#3C4556\" strokelinecap=\"square\" d=\"M60.026 736.434V203.02\"><\/path><path stroke=\"#3C4556\" strokelinecap=\"square\" d=\"M60.364 436.132L-120 436.131l180.364.001zm0-99.873H-120 60.364zm0-99.872H-120 60.364zM128 536.004h-248 248z\" cliprule=\"evenodd\"><\/path><path fill=\"#3C4556\" fillrule=\"evenodd\" d=\"M57.518 535.982a2.286 2.286 0 114.572 0 2.286 2.286 0 01-4.572 0zm0-99.836a2.286 2.286 0 114.572-.002 2.286 2.286 0 01-4.572.002zm0-99.837a2.286 2.286 0 114.572-.002 2.286 2.286 0 01-4.572.002zm0-99.837a2.286 2.286 0 114.572-.002 2.286 2.286 0 01-4.572.002z\" cliprule=\"evenodd\"><\/path><\/g><g opacity=\"0.55\"><path stroke=\"#3C4556\" strokelinecap=\"square\" d=\"M979.195-28.206V397.98m81.185-524.745V397.98\"><\/path><path stroke=\"#3C4556\" strokelinecap=\"square\" d=\"M1141.45 168.46H964h177.45zm0 98.334H964h177.45zm0 98.333H964h177.45zm66.55-295H964h244z\" cliprule=\"evenodd\"><\/path><path fill=\"#3C4556\" fillrule=\"evenodd\" d=\"M1138.66 70.148a2.244 2.244 0 104.49 0 2.246 2.246 0 10-4.49-.001zm-80.21 0c0 1.243 1.01 2.251 2.25 2.251s2.25-1.008 2.25-2.251c0-1.243-1.01-2.251-2.25-2.251s-2.25 1.008-2.25 2.25zm-81.707 0a2.25 2.25 0 104.5.004 2.25 2.25 0 00-4.5-.005zm81.707 98.299a2.252 2.252 0 002.25 2.251 2.252 2.252 0 000-4.503 2.253 2.253 0 00-2.25 2.252zm-81.707 0a2.25 2.25 0 104.498 0 2.25 2.25 0 00-2.249-2.252 2.25 2.25 0 00-2.249 2.252zm161.917-.001a2.244 2.244 0 104.49 0 2.246 2.246 0 10-4.49 0zm0 98.299a2.244 2.244 0 104.49 0 2.246 2.246 0 10-4.49 0zm-80.21 0c0 1.243 1.01 2.251 2.25 2.251s2.25-1.008 2.25-2.251c0-1.243-1.01-2.251-2.25-2.251s-2.25 1.008-2.25 2.251zm-81.707 0a2.25 2.25 0 104.5.002 2.25 2.25 0 00-4.5-.002zm81.707 98.299c0 1.243 1.01 2.251 2.25 2.251s2.25-1.008 2.25-2.251c0-1.243-1.01-2.251-2.25-2.251s-2.25 1.008-2.25 2.251zm-81.707 0a2.25 2.25 0 104.5.002 2.25 2.25 0 00-4.5-.002zm161.917 0a2.244 2.244 0 104.49 0 2.246 2.246 0 10-4.49 0z\" cliprule=\"evenodd\"><\/path><\/g><\/svg><div class=\"bstn-blocks-hero-simple__container\"><div class=\"bstn-blocks-hero-simple__copy-container\"><div class=\"bstn-blocks-hero-simple__subtitle-wrapper\"><p class=\"bstn-blocks-hero-simple__subtitle\">python tutorial<\/p><\/div><h1 class=\"bstn-blocks-hero-simple__title\">Python While Loop<\/h1><p class=\"bstn-blocks-hero-simple__description\"><meta charset=\"utf-8\">Learn more about Python, one of the world\u2019s most versatile and popular programming languages.<\/p><\/div><div class=\"bstn-blocks-hero-simple__image-container\"><\/div><\/div><\/div><\/header>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"is-style-bstn-paragraph-documentation-body\">Python While Loops are a very clever way to run or execute a block of code multiple times with different values. This allows you to write the logic in that block of code only once and provide a different value to be used each time you run the block of code.<\/p>\n\n\n\n<p class=\"is-style-bstn-paragraph-documentation-body\">There are many ways to write loops in Python. One of them is by using a&nbsp;<code>while<\/code>&nbsp;loop. The steps to create and use a while loop are:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Create a variable that holds the initial value.<\/li><li>Start a while loop with a condition that involves the variable created in step 1.<\/li><li>Write the logic inside the while loop that should be executed if the condition is True in step 2. The condition is always checked first and only if it\u2019s True, the logic inside of the while loop will be executed otherwise the code that follows the while loop will be executed.<\/li><li>Change the value of the variable created in step 1 inside the while loop.<\/li><li>Repeat.<\/li><\/ol>\n\n\n\n<p class=\"is-style-bstn-paragraph-documentation-body\">The generic syntax for a while loop is as follows (pay attention to indentation):<\/p>\n\n\n\n<div class=\"wp-block-bstn-blocks-code-snippet bstn-blocks-code-snippet\" data-code-snippet=\"true\"><div class=\"bstn-blocks-code-snippet__title-bar\"><span class=\"bstn-blocks-code-snippet__title\">Code Example<\/span><button class=\"bstn-blocks-code-snippet__copy-trigger\" aria-label=\"Copy code to clipboard\" data-copy-to-clipboard=\"true\"><svg viewbox=\"0 0 12 13\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"bstn-blocks-code-snippet__copy-trigger-icon\"><path d=\"M10.875.5h-7.5c-.633 0-1.125.516-1.125 1.125V2.75H1.125C.492 2.75 0 3.266 0 3.875v7.5A1.11 1.11 0 001.125 12.5h7.5c.61 0 1.125-.492 1.125-1.125V10.25h1.125c.61 0 1.125-.492 1.125-1.125v-7.5A1.14 1.14 0 0010.875.5zm-2.39 10.875h-7.22c-.093 0-.14-.047-.14-.14v-7.22c0-.07.047-.14.14-.14h.985v5.25a1.11 1.11 0 001.125 1.125h5.25v.984c0 .094-.07.141-.14.141zm2.25-2.25h-7.22c-.093 0-.14-.047-.14-.14v-7.22c0-.07.047-.14.14-.14h7.22c.07 0 .14.07.14.14v7.22c0 .093-.07.14-.14.14z\" fill=\"currentColor\"><\/path><\/svg><span data-copy-to-clipboard-text=\"true\">Copy<\/span><\/button><\/div><pre class=\"bstn-blocks-code-snippet__code-snippet-area match-braces line-numbers language-python\" data-language=\"python\" aria-readonly=\"true\"><code>initial_value \nwhile initial_value meets the condition:\n    run this block of code if the condition for the while loop is True\n    change intial_value\nRun this code when condition for the while loop is False<\/code><\/pre><\/div>\n\n\n\n<p class=\"is-style-bstn-paragraph-documentation-body\">Let\u2019s review an example to better understand this. Imagine you want to write a program that prints numbers 1 to 10 but without having to repeat your logic of printing 10 different times. You can achieve this as follows by using a while loop. Please type the code as follows and run your cells in the notebook.<\/p>\n\n\n\n<div class=\"wp-block-bstn-blocks-code-snippet bstn-blocks-code-snippet\" data-code-snippet=\"true\"><div class=\"bstn-blocks-code-snippet__title-bar\"><span class=\"bstn-blocks-code-snippet__title\">Code Example<\/span><button class=\"bstn-blocks-code-snippet__copy-trigger\" aria-label=\"Copy code to clipboard\" data-copy-to-clipboard=\"true\"><svg viewbox=\"0 0 12 13\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"bstn-blocks-code-snippet__copy-trigger-icon\"><path d=\"M10.875.5h-7.5c-.633 0-1.125.516-1.125 1.125V2.75H1.125C.492 2.75 0 3.266 0 3.875v7.5A1.11 1.11 0 001.125 12.5h7.5c.61 0 1.125-.492 1.125-1.125V10.25h1.125c.61 0 1.125-.492 1.125-1.125v-7.5A1.14 1.14 0 0010.875.5zm-2.39 10.875h-7.22c-.093 0-.14-.047-.14-.14v-7.22c0-.07.047-.14.14-.14h.985v5.25a1.11 1.11 0 001.125 1.125h5.25v.984c0 .094-.07.141-.14.141zm2.25-2.25h-7.22c-.093 0-.14-.047-.14-.14v-7.22c0-.07.047-.14.14-.14h7.22c.07 0 .14.07.14.14v7.22c0 .093-.07.14-.14.14z\" fill=\"currentColor\"><\/path><\/svg><span data-copy-to-clipboard-text=\"true\">Copy<\/span><\/button><\/div><pre class=\"bstn-blocks-code-snippet__code-snippet-area match-braces line-numbers language-python\" data-language=\"python\" aria-readonly=\"true\"><code>>>> initial_value = 1\n>>> while initial_value &lt;= 10:\n\u2026 \tprint('initial value is: ', initial_value)\n\u2026 \tinitial_value = initial_value + 1\n\u2026\ninitial value is:\t1\ninitial value is:\t2\ninitial value is:\t3\ninitial value is:\t4\ninitial value is:\t5\ninitial value is:\t6\ninitial value is:\t7\ninitial value is:\t8\ninitial value is:\t9\ninitial value is:\t10\n<\/code><\/pre><\/div>\n\n\n\n<p class=\"is-style-bstn-paragraph-documentation-body\">We have just created our first while loop that prints values 1 to 10 without writing our logic of printing 10 different times. It is very important to change the value of the variable that is used in the condition of the while loop. This should always be done inside of the while loop.<\/p>\n\n\n\n<p class=\"is-style-bstn-paragraph-documentation-body\">We increment the value of&nbsp;<code>initial_value<\/code>&nbsp;by 1 and assign it back into the same variable&nbsp;<code>intial_value<\/code>. This will update the value in&nbsp;<code>initial_value<\/code>&nbsp;to be 1 more than previously. When the value in&nbsp;<code>initial_value<\/code>&nbsp;reaches the value of 11, the while loop condition will fail as it is not less than or equal to 10.<\/p>\n\n\n\n<div class=\"wp-block-bstn-blocks-heading bstn-blocks-heading bstn-blocks-heading--h3 bstn-blocks-heading--mt-0 has-text-align-left\" id=\"exercise-python-loops\"><h2 class=\"bstn-blocks-heading__heading-element\">Exercise: Python Loops<\/h2><\/div>\n\n\n\n<div class=\"wp-block-bstn-blocks-heading bstn-blocks-heading bstn-blocks-heading--h4 bstn-blocks-heading--mt-0 has-text-align-left bstn-blocks-heading--h3\"><h3 class=\"bstn-blocks-heading__heading-element\">Python Loops Exercise Overview<\/h3><\/div>\n\n\n\n<p class=\"is-style-bstn-paragraph-documentation-body\">Let\u2019s put the skills of using while loops into practice by doing a small exercise.<\/p>\n\n\n\n<p class=\"is-style-bstn-paragraph-documentation-body\">Create a new notebook and name it&nbsp;<code>python-loops-exercise<\/code>. Please follow the steps below to implement the exercise. By the end, you will know to loop through a block of code multiple times until the condition remains True.<\/p>\n\n\n\n<div class=\"wp-block-bstn-blocks-heading bstn-blocks-heading bstn-blocks-heading--h4 bstn-blocks-heading--mt-0 has-text-align-left bstn-blocks-heading--h3\"><h3 class=\"bstn-blocks-heading__heading-element\">Python Loops Exercise Instructions<\/h3><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>As part of this exercise, your job is to spend money from a piggy bank until there is none left, however, you can only spend $10 at a time. You will have $100 to start with. Each time you spend money, you will print the remaining amount of money left in the piggy bank.<\/li><li>Create a variable called&nbsp;<code>piggy_bank_balance<\/code>&nbsp;and assign it a value of&nbsp;<code>100<\/code>&nbsp;to start with.<\/li><li>Write a while loop as follows to spend money and print the remaining balance:<ul><li>Start your while loop and put a condition for the loop to check if the&nbsp;<code>piggy_bank_balance<\/code>&nbsp;is greater than zero.<\/li><li>If the condition remains True, inside the while loop,&nbsp;<code>deduct 10<\/code>&nbsp;from the&nbsp;<code>piggy_bank_balance<\/code>&nbsp;and assign the remaining amount back to the same variable&nbsp;<code>piggy_bank_balance<\/code>.<\/li><li>Print&nbsp;<code>piggy_bank_balance<\/code>&nbsp;with a string&nbsp;<code>Remaining Balance<\/code>.<\/li><\/ul><\/li><li>After the while loop ends, print&nbsp;<code>You have spent all your saved money<\/code>.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-bstn-blocks-heading bstn-blocks-heading bstn-blocks-heading--h4 bstn-blocks-heading--mt-0 has-text-align-left bstn-blocks-heading--h3\"><h3 class=\"bstn-blocks-heading__heading-element\">Python Loops Exercise Solution<\/h3><\/div>\n\n\n\n<p class=\"is-style-bstn-paragraph-documentation-body\">Please see the solution below to compare against your code.<\/p>\n\n\n\n<div class=\"wp-block-bstn-blocks-code-snippet bstn-blocks-code-snippet\" data-code-snippet=\"true\"><div class=\"bstn-blocks-code-snippet__title-bar\"><span class=\"bstn-blocks-code-snippet__title\">Code Example<\/span><button class=\"bstn-blocks-code-snippet__copy-trigger\" aria-label=\"Copy code to clipboard\" data-copy-to-clipboard=\"true\"><svg viewbox=\"0 0 12 13\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"bstn-blocks-code-snippet__copy-trigger-icon\"><path d=\"M10.875.5h-7.5c-.633 0-1.125.516-1.125 1.125V2.75H1.125C.492 2.75 0 3.266 0 3.875v7.5A1.11 1.11 0 001.125 12.5h7.5c.61 0 1.125-.492 1.125-1.125V10.25h1.125c.61 0 1.125-.492 1.125-1.125v-7.5A1.14 1.14 0 0010.875.5zm-2.39 10.875h-7.22c-.093 0-.14-.047-.14-.14v-7.22c0-.07.047-.14.14-.14h.985v5.25a1.11 1.11 0 001.125 1.125h5.25v.984c0 .094-.07.141-.14.141zm2.25-2.25h-7.22c-.093 0-.14-.047-.14-.14v-7.22c0-.07.047-.14.14-.14h7.22c.07 0 .14.07.14.14v7.22c0 .093-.07.14-.14.14z\" fill=\"currentColor\"><\/path><\/svg><span data-copy-to-clipboard-text=\"true\">Copy<\/span><\/button><\/div><pre class=\"bstn-blocks-code-snippet__code-snippet-area match-braces line-numbers language-python\" data-language=\"python\" aria-readonly=\"true\"><code>>>> piggy_bank_balance = 100\n>>> while piggy_bank_balance > 0:\n\u2026 \tpiggy_bank_balance = piggy_bank_balance - 10\n\u2026 \tprint('Remaining Balance: ', piggy_bank_balance)\n\u2026\n>>> print('You have spent all your saved money')\nRemaining Balance:\t90\nRemaining Balance:\t80\nRemaining Balance:\t70\nRemaining Balance:\t60\nRemaining Balance:\t50\nRemaining Balance:\t40\nRemaining Balance:\t30\nRemaining Balance:\t20\nRemaining Balance:\t10\nRemaining Balance:\t0\nYou have spent all your saved money\n<\/code><\/pre><\/div>\n\n\n\n<p class=\"is-style-bstn-paragraph-documentation-body\">Great work creating Python programs! As you can see, these fundamental concepts are used to handle data and implement basic functionality. As your skills continue to grow, these foundational concepts will help you write more advanced logic.<\/p>\n\n\n\n<p class=\"is-style-bstn-paragraph-documentation-body\">Now that you have learned the basic syntax of control flow statements and loops, let\u2019s shift our focus to yet another important programming language concept called functions.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:25%\"><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-bstn-blocks-content-navigation-footer bstn-blocks-content-nav-footer bstn-blocks-content-nav-footer--article\"><div class=\"bstn-blocks-content-nav-footer__links-container\"><div class=\"bstn-blocks-content-nav-footer__link-container\"><p class=\"bstn-blocks-content-nav-footer__link-title bstn-blocks-content-nav-footer__link--desktop\">Previous<\/p><a class=\"bstn-blocks-content-nav-footer__link\" href=\"https:\/\/brainstation.io\/learn\/python\/for-loops\"><span class=\"bstn-blocks-content-nav-footer__link-icon-wrapper bstn-blocks-content-nav-footer__link-icon-wrapper--left\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewbox=\"0 0 18 18\" fill=\"none\" class=\"bstn-blocks-content-nav-footer__link-icon bstn-blocks-content-nav-footer__link-icon--left\"><path fill=\"currentColor\" d=\"M6.345 12.743a1 1 0 001.31 1.511l5.477-4.749a1 1 0 000-1.511l-5.477-4.75a1.001 1.001 0 00-1.31 1.512l4.606 3.993-4.606 3.994z\"><\/path><\/svg><\/span><span class=\"bstn-blocks-content-nav-footer__link-text bstn-blocks-content-nav-footer__link--desktop\">Python For Loops<\/span><\/a><\/div><div class=\"bstn-blocks-content-nav-footer__link-container\"><p class=\"bstn-blocks-content-nav-footer__link-title\">Next<\/p><a class=\"bstn-blocks-content-nav-footer__link\" href=\"https:\/\/brainstation.io\/learn\/python\/function\"><span class=\"bstn-blocks-content-nav-footer__link-text\">Python Function<\/span><span class=\"bstn-blocks-content-nav-footer__link-icon-wrapper bstn-blocks-content-nav-footer__link-icon-wrapper--right\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewbox=\"0 0 18 18\" fill=\"none\" class=\"bstn-blocks-content-nav-footer__link-icon bstn-blocks-content-nav-footer__link-icon--right\"><path fill=\"currentColor\" d=\"M6.345 12.743a1 1 0 001.31 1.511l5.477-4.749a1 1 0 000-1.511l-5.477-4.75a1.001 1.001 0 00-1.31 1.512l4.606 3.993-4.606 3.994z\"><\/path><\/svg><\/span><\/a><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-bstn-blocks-container bstn-blocks-container bstn-blocks-container--dark-blue bstn-blocks-container--64 bstn-blocks-container--negative-container bstn-blocks-container--overflow-hidden\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewbox=\"0 0 1140 621\" fill=\"none\" class=\"bstn-blocks-container__bg-flair\"><g opacity=\"0.55\"><path stroke=\"#3C4556\" strokelinecap=\"square\" d=\"M60.026 736.434V203.02\"><\/path><path stroke=\"#3C4556\" strokelinecap=\"square\" d=\"M60.364 436.132L-120 436.131l180.364.001zm0-99.873H-120 60.364zm0-99.872H-120 60.364zM128 536.004h-248 248z\" cliprule=\"evenodd\"><\/path><path fill=\"#3C4556\" fillrule=\"evenodd\" d=\"M57.518 535.982a2.286 2.286 0 114.572 0 2.286 2.286 0 01-4.572 0zm0-99.836a2.286 2.286 0 114.572-.002 2.286 2.286 0 01-4.572.002zm0-99.837a2.286 2.286 0 114.572-.002 2.286 2.286 0 01-4.572.002zm0-99.837a2.286 2.286 0 114.572-.002 2.286 2.286 0 01-4.572.002z\" cliprule=\"evenodd\"><\/path><\/g><g opacity=\"0.55\"><path stroke=\"#3C4556\" strokelinecap=\"square\" d=\"M979.195-28.206V397.98m81.185-524.745V397.98\"><\/path><path stroke=\"#3C4556\" strokelinecap=\"square\" d=\"M1141.45 168.46H964h177.45zm0 98.334H964h177.45zm0 98.333H964h177.45zm66.55-295H964h244z\" cliprule=\"evenodd\"><\/path><path fill=\"#3C4556\" fillrule=\"evenodd\" d=\"M1138.66 70.148a2.244 2.244 0 104.49 0 2.246 2.246 0 10-4.49-.001zm-80.21 0c0 1.243 1.01 2.251 2.25 2.251s2.25-1.008 2.25-2.251c0-1.243-1.01-2.251-2.25-2.251s-2.25 1.008-2.25 2.25zm-81.707 0a2.25 2.25 0 104.5.004 2.25 2.25 0 00-4.5-.005zm81.707 98.299a2.252 2.252 0 002.25 2.251 2.252 2.252 0 000-4.503 2.253 2.253 0 00-2.25 2.252zm-81.707 0a2.25 2.25 0 104.498 0 2.25 2.25 0 00-2.249-2.252 2.25 2.25 0 00-2.249 2.252zm161.917-.001a2.244 2.244 0 104.49 0 2.246 2.246 0 10-4.49 0zm0 98.299a2.244 2.244 0 104.49 0 2.246 2.246 0 10-4.49 0zm-80.21 0c0 1.243 1.01 2.251 2.25 2.251s2.25-1.008 2.25-2.251c0-1.243-1.01-2.251-2.25-2.251s-2.25 1.008-2.25 2.251zm-81.707 0a2.25 2.25 0 104.5.002 2.25 2.25 0 00-4.5-.002zm81.707 98.299c0 1.243 1.01 2.251 2.25 2.251s2.25-1.008 2.25-2.251c0-1.243-1.01-2.251-2.25-2.251s-2.25 1.008-2.25 2.251zm-81.707 0a2.25 2.25 0 104.5.002 2.25 2.25 0 00-4.5-.002zm161.917 0a2.244 2.244 0 104.49 0 2.246 2.246 0 10-4.49 0z\" cliprule=\"evenodd\"><\/path><\/g><\/svg><div class=\"bstn-blocks-container__wrapper bstn-blocks-container__wrapper--readable-width bstn-blocks-container__wrapper--negative-container\">\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-2 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-bstn-blocks-heading bstn-blocks-heading bstn-blocks-heading--h2 has-text-align-left bstn-blocks-heading--divider\"><h2 class=\"bstn-blocks-heading__heading-element\">Learn Python Today<\/h2><\/div>\n\n\n\n<p>Get hands-on experience writing code with interactive tutorials in our free online learning platform. <\/p>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ul class=\"wp-block-list is-style-kg-list-checklist-alternate\"><li>Free and fun<\/li><li>Designed for beginners<\/li><li>No downloads or setup required<\/li><\/ul>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-bstn-button-primary\"><a class=\"wp-block-button__link\" href=\"https:\/\/brainstation.io\/learn\/python\" target=\"_blank\" rel=\"noreferrer noopener\">Get Started<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-video\"><video autoplay loop muted src=\"https:\/\/d3ghupt9z9s6o0.cloudfront.net\/app\/uploads\/2022\/04\/13110643\/Python-promo-clip.mp4\" playsinline><\/video><\/figure>\n<\/div>\n<\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Python While Loops are a very clever way to run or execute a block of code multiple times with different values. This allows you to write the logic in that block of code only once and provide a different value to be used each time you run the block of code. There are many ways [&hellip;]<\/p>\n","protected":false},"featured_media":0,"parent":130131,"menu_order":0,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-130083","codex-reference","type-codex-reference","status-publish","format-standard","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/brainstation.io\/wp\/api\/wp\/v2\/codex-reference\/130083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brainstation.io\/wp\/api\/wp\/v2\/codex-reference"}],"about":[{"href":"https:\/\/brainstation.io\/wp\/api\/wp\/v2\/types\/codex-reference"}],"version-history":[{"count":9,"href":"https:\/\/brainstation.io\/wp\/api\/wp\/v2\/codex-reference\/130083\/revisions"}],"predecessor-version":[{"id":133056,"href":"https:\/\/brainstation.io\/wp\/api\/wp\/v2\/codex-reference\/130083\/revisions\/133056"}],"up":[{"embeddable":true,"href":"https:\/\/brainstation.io\/wp\/api\/wp\/v2\/codex-reference\/130131"}],"wp:attachment":[{"href":"https:\/\/brainstation.io\/wp\/api\/wp\/v2\/media?parent=130083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brainstation.io\/wp\/api\/wp\/v2\/categories?post=130083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brainstation.io\/wp\/api\/wp\/v2\/tags?post=130083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}