{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e6fede1b",
   "metadata": {},
   "source": [
    "# While Loop Review\n",
    "\n",
    "01. When might you prefer a `for` loop in place of a `while` loop?\n",
    "    What do you gain?\n",
    "\n",
    "02. When might you prefer a while loop or a foreach instead of a for loop?\n",
    "\n",
    "03. Describe in general when a `foreach` loop is going to be easier to use\n",
    "    than a `while` loop.\n",
    "\n",
    "04. Each sentence below introduces a problem.\n",
    "    What words/combinations suggest a loop/repetition?\n",
    "\n",
    "    1. Square each number from 1 to n.\n",
    "    2. Respond until the user says to stop.\n",
    "    3. Repeat the process until the width is < .00001.\n",
    "    4. Count the vowels in the sentence that you are given.\n",
    "    5. See if there are any double letters in the word that you are given.\n",
    "\n",
    "05. Compare do-while and while loops:\n",
    "    How do you think about which one to use?\n",
    "\n",
    "06. In general, what causes an infinite `while` loop?\n",
    "\n",
    "07. A `while` loop is generally terminated when the program evaluates the\n",
    "    condition in its heading and it becomes false.\n",
    "    How else can a program exit from a `while` loop?\n",
    "\n",
    "08. When inside a loop,\n",
    "    a return statement should generally only appear as a *sub-statement*\n",
    "    of what kind of statement?\n",
    "\n",
    "09. Which of these conditions is safer in general, with *arbitrary*\n",
    "    `string` `s` and\n",
    "    `int` `i`?\n",
    "\n",
    "    ```\n",
    "    s[i] != '#' && i >= 0 && i < s.Length\n",
    "\n",
    "    i >= 0 && i < s.Length && s[i] != '#'\n",
    "    ```\n",
    "\n",
    "10. What is printed?\n",
    "```csharp\n",
    "int value = 3;\n",
    "while (value > 0)\n",
    "{\n",
    "    Console.WriteLine(value);\n",
    "    value--;\n",
    "}\n",
    "Console.WriteLine(\"Done\");\n",
    "```\n",
    "\n",
    "How would the output change if `value` started at zero? Explain when the condition is tested.\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}
