{"id":445,"date":"2025-05-19T19:32:46","date_gmt":"2025-05-19T19:32:46","guid":{"rendered":"https:\/\/buhave.com\/courses\/?p=445"},"modified":"2026-06-06T11:33:22","modified_gmt":"2026-06-06T11:33:22","slug":"control-flow-2","status":"publish","type":"post","link":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/","title":{"rendered":"Control Flow"},"content":{"rendered":"<h2>if, elif, and else statements<\/h2>\n<p>These statements let your program make decisions based on conditions \u2014 they\u2019re the core of control flow in Python. For beginners, see our <a href=\"https:\/\/buhave.com\/courses\/python\/introduction-to-python\/\" title=\"Introduction to Python\">Introduction to Python<\/a> lesson to get started, and our <a href=\"https:\/\/buhave.com\/courses\/python\/loops-and-iteration-2\/\" title=\"Loops and Iteration\">Loops and Iteration<\/a> module for how these conditions interact with repeatable tasks.<\/p>\n<h3>Basic Syntax<\/h3>\n<p style=\"text-align: center\"><em>if condition:<\/em><br \/>\n<em># code block if condition is True<\/em><br \/>\n<em>elif another_condition:<\/em><br \/>\n<em># code block if elif is True<\/em><br \/>\n<em>else:<\/em><br \/>\n<em># code block if none are True<\/em><\/p>\n<ul>\n<li>Each condition is checked in order<\/li>\n<li>Indentation (typically 4 spaces) defines code blocks<\/li>\n<li>You can have one if, zero or more elif, and zero or one else<\/li>\n<\/ul>\n<p><strong>Simple Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>temperature = 25<\/em><\/p>\n<p style=\"text-align: center\"><em>if temperature &gt; 30:<\/em><br \/>\n<em>print(&#8220;It&#8217;s hot outside.&#8221;)<\/em><br \/>\n<em>elif temperature &gt;= 20:<\/em><br \/>\n<em>print(&#8220;It&#8217;s a nice day.&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;It\u2019s cold outside.&#8221;)<\/em><\/p>\n<p><strong>Output:<\/strong> &#8220;It&#8217;s a nice day.&#8221;<\/p>\n<p><strong>Flow Explanation:<\/strong><\/p>\n<ul>\n<li>If the if condition is True, it runs that block and skips the rest.<\/li>\n<li>If the if is False, Python checks the elif (if any).<\/li>\n<li>If none of the conditions are True, the else block runs.<\/li>\n<\/ul>\n<p><strong>Real-Life Example: Age Check<\/strong><\/p>\n<p style=\"text-align: center\"><em>age = int(input(&#8220;Enter your age: &#8220;))<\/em><\/p>\n<p style=\"text-align: center\"><em>if age &lt; 13:<\/em><br \/>\n<em>print(&#8220;You are a child.&#8221;)<\/em><br \/>\n<em>elif age &lt; 18:<\/em><br \/>\n<em>print(&#8220;You are a teenager.&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;You are an adult.&#8221;)<\/em><\/p>\n<p><strong>Nestings and Practical Use<\/strong><\/p>\n<p>You can nest conditions inside others:<\/p>\n<p style=\"text-align: center\"><em>score = 85<\/em><\/p>\n<p style=\"text-align: center\"><em>if score &gt;= 50:<\/em><br \/>\n<em>print(&#8220;You passed!&#8221;)<\/em><br \/>\n<em>if score &gt;= 80:<\/em><br \/>\n<em>print(&#8220;Great job!&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;You failed.&#8221;)<\/em><\/p>\n<p><strong>Common Mistakes to Avoid<\/strong><\/p>\n<table style=\"width: 100%;border-collapse: collapse;font-family: Arial, sans-serif;margin: 20px 0\">\n<thead>\n<tr>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Mistake<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Fix<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Missing colon <code>:<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Add a colon at end of condition<br \/>\n<code>if x == 5<\/code> \u2192 <code>if x == 5:<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Improper indentation<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Use consistent 4-space indentation<br \/>\n<code>print(\"Hello\")<\/code> \u2192 <code> print(\"Hello\")<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Using <code>=<\/code> instead of <code>==<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>=<\/code> is assignment, <code>==<\/code> is comparison<br \/>\n<code>if x = 5:<\/code> \u2192 <code>if x == 5:<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Forgetting to cast <code>input()<\/code> to <code>int<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Use <code>int(input())<\/code> if comparing numbers<br \/>\n<code>age = input()<\/code> \u2192 <code>age = int(input())<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Quick Quiz<\/strong><\/p>\n<p>What will this print?<\/p>\n<p style=\"text-align: center\"><em>x = 10<\/em><\/p>\n<p style=\"text-align: center\"><em>if x &gt; 20:<\/em><br \/>\n<em>print(&#8220;A&#8221;)<\/em><br \/>\n<em>elif x &gt; 5:<\/em><br \/>\n<em>print(&#8220;B&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;C&#8221;)<\/em><\/p>\n<p>Answer: &#8220;B&#8221;<\/p>\n<p><strong>Summary Table:<\/strong><\/p>\n<table style=\"width: 100%;border-collapse: collapse;font-family: Arial, sans-serif;margin: 20px 0\">\n<thead>\n<tr>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Statement<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Purpose<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>if<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Starts a conditional check<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>elif<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Checks another condition if the previous <code>if<\/code> or <code>elif<\/code> fails<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>else<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Runs if no <code>if<\/code> or <code>elif<\/code> conditions are met<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Truthy and falsy values<\/h2>\n<p>In Python, every value has an inherent Boolean value \u2014 either True or False \u2014 even if it\u2019s not literally the TrueorFalse` Boolean type. For a deeper understanding of how Python determines truthiness, check our <a href=\"https:\/\/buhave.com\/courses\/python\/variables-data-types-and-operators\/\" title=\"Variables, Data Types and Operators\">Variables, Data Types and Operators<\/a> lesson.<\/p>\n<p>These values are evaluated when used in conditions, such as in if statements. For more on how different types behave in Boolean contexts, our <a href=\"https:\/\/buhave.com\/courses\/python\/introduction-to-python\/\" title=\"Introduction to Python\">Introduction to Python<\/a> overview is a great starting point.<\/p>\n<h3>What are &#8220;Truthy&#8221; and &#8220;Falsy&#8221;?<\/h3>\n<ul>\n<li>Truthy: A value that evaluates to True when used in a Boolean context.<\/li>\n<li>Falsy: A value that evaluates to False.<\/li>\n<\/ul>\n<p><strong>Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>if &#8220;hello&#8221;:<\/em><br \/>\n<em>print(&#8220;This is truthy.&#8221;)<\/em><\/p>\n<p><strong>Output:<\/strong> This is truthy.<\/p>\n<ul>\n<li>Because a non-empty string (&#8220;hello&#8221;) is considered truthy.<\/li>\n<\/ul>\n<p><strong>Falsy Values in Python<\/strong><\/p>\n<p>These values are considered False in Boolean contexts:<\/p>\n<table style=\"width: 100%;border-collapse: collapse;font-family: Arial, sans-serif;margin: 20px 0\">\n<thead>\n<tr>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Type<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Falsy Value<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Boolean<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>False<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">NoneType<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>None<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Numeric<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>0<\/code>, <code>0.0<\/code>, <code>0j<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Sequence\/Collection<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>''<\/code> (empty string),<br \/>\n<code>[]<\/code> (empty list),<br \/>\n<code>()<\/code> (empty tuple),<br \/>\n<code>{}<\/code> (empty dict),<br \/>\n<code>set()<\/code> (empty set)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Custom object<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Any object with <code>__bool__()<\/code> or <code>__len__()<\/code> returning <code>False<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: center\"><em># All of these evaluate as False<\/em><br \/>\n<em>if not &#8220;&#8221;:<\/em><br \/>\n<em>print(&#8220;Empty string is falsy&#8221;)<\/em><\/p>\n<p style=\"text-align: center\"><em>if not 0:<\/em><br \/>\n<em>print(&#8220;Zero is falsy&#8221;)<\/em><\/p>\n<p style=\"text-align: center\"><em>if not None:<\/em><br \/>\n<em>print(&#8220;None is falsy&#8221;)<\/em><\/p>\n<p style=\"text-align: center\"><em>if not []:<\/em><br \/>\n<em>print(&#8220;Empty list is falsy&#8221;)<\/em><\/p>\n<p><strong>Truthy Values in Python<\/strong><\/p>\n<p>Everything else not listed as falsy is truthy.<\/p>\n<p><strong>Examples:<\/strong><\/p>\n<p style=\"text-align: center\"><em>&#8220;hello&#8221; # non-empty string<\/em><br \/>\n<em>42 # any non-zero number<\/em><br \/>\n<em>[1, 2, 3] # non-empty list<\/em><br \/>\n<em>{&#8220;a&#8221;: 1} # non-empty dictionary<\/em><br \/>\n<em>True # obviously!<\/em><\/p>\n<p><strong>These will all make if statements run:<\/strong><\/p>\n<p style=\"text-align: center\"><em>if [1, 2, 3]:<\/em><br \/>\n<em>print(&#8220;Truthy list!&#8221;)<\/em><\/p>\n<p style=\"text-align: center\"><em>if &#8220;Python&#8221;:<\/em><br \/>\n<em>print(&#8220;Truthy string!&#8221;)<\/em><\/p>\n<p><strong>Boolean Context Examples:<\/strong><\/p>\n<p style=\"text-align: center\"><em>x = []<\/em><\/p>\n<p style=\"text-align: center\"><em>if x:<\/em><br \/>\n<em>print(&#8220;List has items.&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;List is empty.&#8221;)<\/em><\/p>\n<p><strong>Output:<\/strong> List is empty.<\/p>\n<p><strong>Using bool() to Check Value Truthiness<\/strong><\/p>\n<p>You can test how Python evaluates any value using bool():<\/p>\n<p style=\"text-align: center\"><em>print(bool(0)) # False<\/em><br \/>\n<em>print(bool(&#8220;Hi&#8221;)) # True<\/em><br \/>\n<em>print(bool([])) # False<\/em><br \/>\n<em>print(bool([0])) # True (non-empty list!)<\/em><\/p>\n<p><strong>Summary:<\/strong><\/p>\n<table style=\"width: 100%;border-collapse: collapse;font-family: Arial, sans-serif;margin: 20px 0\">\n<thead>\n<tr>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Value Type<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Truthy Example<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #000;font-weight: bold\"><strong>Falsy Example<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">String<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>\"Python\"<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>\"\"<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Number<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>42<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>0<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">List<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>[1, 2]<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>[]<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Dictionary<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>{\"a\": 1}<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>{}<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">Boolean<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>True<\/code><\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>False<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">NoneType<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\">\u2014<\/td>\n<td style=\"padding: 10px;border-bottom: 1px solid #ddd\"><code>None<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Nested conditionals<\/h2>\n<h3>What Are Nested Conditionals?<\/h3>\n<ul>\n<li>A nested conditional is when you place an if, elif, or else inside another if block.<\/li>\n<li>This lets you check multiple layers of logic, like decision trees.<\/li>\n<\/ul>\n<p><strong>Basic Syntax:<\/strong><\/p>\n<p style=\"text-align: center\"><em>if condition1:<\/em><br \/>\n<em>if condition2:<\/em><br \/>\n<em># Runs if both condition1 AND condition2 are True<\/em><br \/>\n<em>else:<\/em><br \/>\n<em># Runs if condition1 is True but condition2 is False<\/em><br \/>\n<em>else:<\/em><br \/>\n<em># Runs if condition1 is False<\/em><\/p>\n<p><strong>Simple Example:<\/strong><\/p>\n<p style=\"text-align: center\"><em>age = 20<\/em><br \/>\n<em>has_ticket = True<\/em><\/p>\n<p style=\"text-align: center\"><em>if age &gt;= 18:<\/em><br \/>\n<em>if has_ticket:<\/em><br \/>\n<em>print(&#8220;You can enter the event.&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;You need a ticket to enter.&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;You must be 18 or older to enter.&#8221;)<\/em><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p>You can enter the event.<\/p>\n<p><strong>Why Use Nested Conditionals?<\/strong><\/p>\n<ul>\n<li>When one condition depends on another<\/li>\n<li>To create multi-level decision structures<\/li>\n<li>When you want to check a second condition only if the first is True<\/li>\n<\/ul>\n<p><strong>Example:<\/strong> Student Grading System<\/p>\n<p style=\"text-align: center\"><em>grade = 85<\/em><\/p>\n<p style=\"text-align: center\"><em>if grade &gt;= 50:<\/em><br \/>\n<em>if grade &gt;= 90:<\/em><br \/>\n<em>print(&#8220;A+&#8221;)<\/em><br \/>\n<em>elif grade &gt;= 80:<\/em><br \/>\n<em>print(&#8220;A&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;Pass&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;Fail&#8221;)<\/em><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p>A<\/p>\n<p><strong>Alternative: Combine Conditions with and<\/strong><\/p>\n<p>You can sometimes flatten nested conditionals by using and:<\/p>\n<p style=\"text-align: center\"><em>if age &gt;= 18 and has_ticket:<\/em><br \/>\n<em>print(&#8220;You can enter.&#8221;)<\/em><br \/>\n<em>elif age &gt;= 18:<\/em><br \/>\n<em>print(&#8220;Get a ticket.&#8221;)<\/em><br \/>\n<em>else:<\/em><br \/>\n<em>print(&#8220;You&#8217;re too young.&#8221;)<\/em><\/p>\n<p>Both versions are valid \u2014 use nesting for clarity when conditions are hierarchical.<\/p>\n<p><strong>Common Mistakes to Avoid<\/strong><\/p>\n<table style=\"width: 100%;border-collapse: collapse;font-family: Arial, sans-serif;margin: 20px 0\">\n<thead>\n<tr style=\"background-color: #f8f9fa\">\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #dee2e6;font-weight: 600\"><strong>Mistake<\/strong><\/th>\n<th style=\"padding: 12px;text-align: left;border-bottom: 2px solid #dee2e6;font-weight: 600\"><strong>Fix<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n","protected":false},"excerpt":{"rendered":"<p>if, elif, and else statements These statements let your program make decisions based on conditions \u2014 they\u2019re the core of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":446,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[9],"tags":[],"class_list":["post-445","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Control Flow -<\/title>\n<meta name=\"description\" content=\"Control Flow in Python manages the execution path of a program using conditions, loops, and decision-making structures.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/buhave.com\/courses\/python\/control-flow-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Control Flow -\" \/>\n<meta property=\"og:description\" content=\"Control Flow in Python manages the execution path of a program using conditions, loops, and decision-making structures.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/buhave.com\/courses\/python\/control-flow-2\/\" \/>\n<meta property=\"og:site_name\" content=\"BUHAVE\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BeYouHave\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/naveedsafdarawan\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-19T19:32:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-06T11:33:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Control-Flow.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Naveed Safdar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Naveed Safdar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/\"},\"author\":{\"name\":\"Naveed Safdar\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\"},\"headline\":\"Control Flow\",\"datePublished\":\"2025-05-19T19:32:46+00:00\",\"dateModified\":\"2026-06-06T11:33:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/\"},\"wordCount\":823,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Control-Flow.webp\",\"articleSection\":[\"Python Course\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/\",\"name\":\"Control Flow -\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Control-Flow.webp\",\"datePublished\":\"2025-05-19T19:32:46+00:00\",\"dateModified\":\"2026-06-06T11:33:22+00:00\",\"description\":\"Control Flow in Python manages the execution path of a program using conditions, loops, and decision-making structures.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/#primaryimage\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Control-Flow.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/Control-Flow.webp\",\"width\":1200,\"height\":628,\"caption\":\"Control Flow\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/python\\\/control-flow-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Courses\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Course\",\"item\":\"https:\\\/\\\/buhave.com\\\/courses\\\/learn\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Control Flow\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#website\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"name\":\"BUHAVE\",\"description\":\"Courses - Learn Online for Free\",\"publisher\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/buhave.com\\\/courses\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#organization\",\"name\":\"BUHAVE\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"contentUrl\":\"https:\\\/\\\/buhave.com\\\/courses\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/buhave-course.webp\",\"width\":375,\"height\":75,\"caption\":\"BUHAVE\"},\"image\":{\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/BeYouHave\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/buhave\",\"https:\\\/\\\/www.youtube.com\\\/@buhave\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/buhave.com\\\/courses\\\/#\\\/schema\\\/person\\\/04fe0254e118521c9fbb3da39de5acca\",\"name\":\"Naveed Safdar\",\"description\":\"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/naveedsafdar\\\/\",\"https:\\\/\\\/www.facebook.com\\\/naveedsafdarawan\\\/\",\"https:\\\/\\\/www.youtube.com\\\/@naveedsafdar\"],\"url\":\"https:\\\/\\\/buhave.com\\\/courses\\\/author\\\/naveed-safdar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Control Flow -","description":"Control Flow in Python manages the execution path of a program using conditions, loops, and decision-making structures.","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:\/\/buhave.com\/courses\/python\/control-flow-2\/","og_locale":"en_US","og_type":"article","og_title":"Control Flow -","og_description":"Control Flow in Python manages the execution path of a program using conditions, loops, and decision-making structures.","og_url":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/","og_site_name":"BUHAVE","article_publisher":"https:\/\/www.facebook.com\/BeYouHave\/","article_author":"https:\/\/www.facebook.com\/naveedsafdarawan\/","article_published_time":"2025-05-19T19:32:46+00:00","article_modified_time":"2026-06-06T11:33:22+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Control-Flow.webp","type":"image\/webp"}],"author":"Naveed Safdar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Naveed Safdar","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/#article","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/"},"author":{"name":"Naveed Safdar","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca"},"headline":"Control Flow","datePublished":"2025-05-19T19:32:46+00:00","dateModified":"2026-06-06T11:33:22+00:00","mainEntityOfPage":{"@id":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/"},"wordCount":823,"commentCount":0,"publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"image":{"@id":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Control-Flow.webp","articleSection":["Python Course"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/buhave.com\/courses\/python\/control-flow-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/","url":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/","name":"Control Flow -","isPartOf":{"@id":"https:\/\/buhave.com\/courses\/#website"},"primaryImageOfPage":{"@id":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/#primaryimage"},"image":{"@id":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/#primaryimage"},"thumbnailUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Control-Flow.webp","datePublished":"2025-05-19T19:32:46+00:00","dateModified":"2026-06-06T11:33:22+00:00","description":"Control Flow in Python manages the execution path of a program using conditions, loops, and decision-making structures.","breadcrumb":{"@id":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/buhave.com\/courses\/python\/control-flow-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/#primaryimage","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Control-Flow.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/04\/Control-Flow.webp","width":1200,"height":628,"caption":"Control Flow"},{"@type":"BreadcrumbList","@id":"https:\/\/buhave.com\/courses\/python\/control-flow-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Courses","item":"https:\/\/buhave.com\/courses\/"},{"@type":"ListItem","position":2,"name":"Python Course","item":"https:\/\/buhave.com\/courses\/learn\/python\/"},{"@type":"ListItem","position":3,"name":"Control Flow"}]},{"@type":"WebSite","@id":"https:\/\/buhave.com\/courses\/#website","url":"https:\/\/buhave.com\/courses\/","name":"BUHAVE","description":"Courses - Learn Online for Free","publisher":{"@id":"https:\/\/buhave.com\/courses\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/buhave.com\/courses\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/buhave.com\/courses\/#organization","name":"BUHAVE","url":"https:\/\/buhave.com\/courses\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/","url":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","contentUrl":"https:\/\/buhave.com\/courses\/wp-content\/uploads\/2025\/03\/buhave-course.webp","width":375,"height":75,"caption":"BUHAVE"},"image":{"@id":"https:\/\/buhave.com\/courses\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/BeYouHave\/","https:\/\/www.linkedin.com\/company\/buhave","https:\/\/www.youtube.com\/@buhave"]},{"@type":"Person","@id":"https:\/\/buhave.com\/courses\/#\/schema\/person\/04fe0254e118521c9fbb3da39de5acca","name":"Naveed Safdar","description":"I\u2019m Naveed Safdar - SEO Manager with over 10 years of experience in SEO and Digital Marketing. I\u2019ve had the privilege of working with leading national and international companies including Grafdom, PakWheels, Systems Limited, Confiz, Educative, and Dubizzle Labs. My expertise spans technical SEO, content strategy, organic growth, and performance analytics - helping businesses improve visibility, traffic, and ROI.","sameAs":["https:\/\/www.linkedin.com\/in\/naveedsafdar\/","https:\/\/www.facebook.com\/naveedsafdarawan\/","https:\/\/www.youtube.com\/@naveedsafdar"],"url":"https:\/\/buhave.com\/courses\/author\/naveed-safdar\/"}]}},"_links":{"self":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/comments?post=445"}],"version-history":[{"count":2,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/445\/revisions"}],"predecessor-version":[{"id":1120,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/posts\/445\/revisions\/1120"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media\/446"}],"wp:attachment":[{"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/media?parent=445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/categories?post=445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buhave.com\/courses\/wp-json\/wp\/v2\/tags?post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}