{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ch03-title",
   "metadata": {},
   "source": [
    "# Control Flow"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch03-overview",
   "metadata": {},
   "source": [
    "Control flow lets a program decide what to do next. This chapter introduces the branching and looping structures that turn straight-line code into programs that respond to data.\n",
    "\n",
    "- Conditional statements with `if`, `elif`, and `else`\n",
    "- `for` loops for iterating over data\n",
    "- `while` loops for condition-based repetition\n",
    "- Loop-control keywords for special cases\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0300-video",
   "metadata": {},
   "source": [
    "<h2>Chapter Video</h2>\n",
    "\n",
    "This overview introduces Boolean expressions and conditional branches with if, elif, and else.\n",
    "\n",
    "```{raw} html\n",
    "<iframe width=\"100%\" height=\"400\" src=\"https://www.youtube-nocookie.com/embed/DZwmZ8Usvnk\" title=\"Python Tutorial for Beginners 6: Conditionals and Booleans - If, Else, and Elif Statements\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen referrerpolicy=\"strict-origin-when-cross-origin\"></iframe>\n",
    "```\n",
    "\n",
    "> *[Python Tutorial for Beginners 6: Conditionals and Booleans - If, Else, and Elif Statements (16:28)](https://youtube.com/watch?v=DZwmZ8Usvnk) by Corey Schafer*\n",
    ">\n",
    "> Hosted on YouTube; property of its original creator, embedded here for educational reference only."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch03-goals",
   "metadata": {},
   "source": [
    "<h2>Learning Objectives</h2>\n",
    "\n",
    "By the end of this chapter, you will be able to:\n",
    "\n",
    "1. Use conditional statements to choose between branches of code\n",
    "2. Write `for` and `while` loops for repeated work\n",
    "3. Use `break`, `continue`, and `pass` intentionally\n",
    "4. Trace how control moves through nested branches and loops\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch03-flow",
   "metadata": {},
   "source": [
    "<h2>Chapter Flow</h2>\n",
    "\n",
    "```{container} chapter-flow\n",
    "1. {doc}`0301-conditionals`\n",
    "2. {doc}`0302-iteration`\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ch03-glossary",
   "metadata": {},
   "source": [
    "<h2>Glossary</h2>\n",
    "\n",
    "| # | Term | Explanation |\n",
    "|---:|---|---|\n",
    "| 1 | Control flow | The order in which a program runs statements. |\n",
    "| 2 | Conditional statement | A statement that chooses whether to run code based on a condition. |\n",
    "| 3 | Boolean expression | An expression that evaluates to `True` or `False`. |\n",
    "| 4 | Branch | One possible path through a conditional statement. |\n",
    "| 5 | `if` statement | A conditional statement that runs a block only when its condition is true. |\n",
    "| 6 | `else` clause | The branch that runs when the `if` condition is false. |\n",
    "| 7 | `elif` clause | A chained conditional branch that tests another condition. |\n",
    "| 8 | Nested conditional | A conditional statement placed inside another conditional statement. |\n",
    "| 9 | Conditional expression | A compact expression that chooses between two values. |\n",
    "| 10 | Iteration | Repeating a block of code. |\n",
    "| 11 | Iterable | An object that can provide its items one at a time. |\n",
    "| 12 | Iterator | An object that tracks its position while producing items one at a time. |\n",
    "| 13 | `for` loop | A loop that repeats once for each item in an iterable. |\n",
    "| 14 | `range` | A built-in type commonly used to generate integer sequences for loops. |\n",
    "| 15 | `while` loop | A loop that repeats while a condition remains true. |\n",
    "| 16 | Sentinel | A special value that signals when a data-controlled loop should stop. |\n",
    "| 17 | Infinite loop | A loop whose condition never becomes false unless something interrupts it. |\n",
    "| 18 | `break` statement | A statement that exits the nearest enclosing loop immediately. |\n",
    "| 19 | `continue` statement | A statement that skips the rest of the current loop iteration. |\n",
    "| 20 | Running total | A variable updated inside a loop to accumulate a total such as total rainfall. |\n",
    "| 21 | Accumulator pattern | A loop pattern that initializes a variable before the loop, updates it on each iteration, and uses the result after the loop. |\n",
    "| 22 | Trace table | A table that records the value of each variable after every loop iteration, used to check how a loop behaves. |\n",
    "| 23 | Chained conditional | A conditional statement with one or more `elif` clauses that tests conditions in order and runs only the first true branch. |\n",
    "| 24 | `pass` statement | A statement that does nothing, used as a placeholder where Python requires a block. |\n",
    "| 25 | Loop variable | The variable in a `for` loop header that holds the current item on each iteration. |\n",
    "| 26 | Nested loop | A loop inside the body of another loop; the inner loop finishes all its iterations for each iteration of the outer loop. |\n",
    "| 27 | Off-by-one error | A bug where a loop or index runs one step too many or too few, often from using `<=` where `<` is needed. |\n",
    "| 28 | `enumerate` | A built-in function that produces each item of an iterable together with its index. |\n",
    "| 29 | `zip` | A built-in function that pairs up items from two or more iterables so you can loop over them in parallel. |\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0300-slides",
   "metadata": {},
   "source": [
    "<h2><a href=\"overview.html\" target=\"_blank\" style=\"color: var(--pst-color-link, #176de8);\">Chapter Overview Slides</a></h2>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
