{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "962ffbca-649e-4de3-83d7-482538741f52",
   "metadata": {},
   "source": [
    "# Chapter Review\n",
    "\n",
    "- Note that the course policy is that you should not use generative AI\n",
    "  without authorization. If you are suspected to have used generative AI\n",
    "  and not able to explain/reproduce your work when requested, all your\n",
    "  **related assignments throughout the semester will be regraded as 0.**\n",
    "- Prepare this assignment using a Word document.\n",
    "- Number and write answers under each question.\n",
    "- Paste code screenshots when required.\n",
    "\n",
    "You are encourage to keep your test code in the project. To do that:\n",
    "\n",
    "- Create a dotnet console app project ({ref}`create-project`), if you\n",
    "  have not done that, in your *USERNAME*/workspace/introcscs directory; called it\n",
    "  **Ch05ForLoop**.\n",
    "- Place your test code in methods to be called from the Main method. Name your\n",
    "  methods properly.\n",
    "\n",
    "1.  When you have nested `for` loops, and you reach the bottom of the *body* of the\n",
    "    *inner* loop, where does execution go next?\n",
    "\n",
    "2.  What happens when you omit the condition in a `for` loop?\n",
    "\n",
    "    Explain and try it out in csharprepl or VS Code and paste the results here.\n",
    "\n",
    "3.  In the heading of a `for` loop, how do you initialize or update\n",
    "    several variables?\n",
    "\n",
    "4.  Rewrite\n",
    "\n",
    "        num /= 2;\n",
    "\n",
    "    equivalently without the operand `/=`.\n",
    "\n",
    "5.  Rewrite\n",
    "\n",
    "        bigName = bigName - 10;\n",
    "\n",
    "    with a statement that only includes `bigName` once.\n",
    "\n",
    "6.  Distinguish the effects of these two statements:\n",
    "\n",
    "        x-=2;\n",
    "\n",
    "        x=-2;\n",
    "\n",
    "7.  What is printed?\n",
    "\n",
    "        Console.WriteLine(\"12345678\");\n",
    "        for( int p = 1; p < 6; p++) {\n",
    "            string formatStr = \"{0:F\" + p + \"}\";\n",
    "            Console.WriteLine(formatStr, 1.2345678);\n",
    "        }\n",
    "\n",
    "    Explain, then paste here the screenshot of the results of you testing it in csharprepl or VS Code.\n",
    "\n",
    "8.  What is printed? (Just “,4” has been inserted.)\n",
    "\n",
    "        Console.WriteLine(\"12345678\");\n",
    "        for( int p = 1; p < 6; p++) {\n",
    "            string formatStr = \"{0,4:F\" + p + \"}\";\n",
    "            Console.WriteLine(formatStr, 1.2345678);\n",
    "        }\n",
    "\n",
    "    Explain, then paste here the screenshot of the results of you testing it in csharprepl or VS Code.\n",
    "\n",
    "9.  What is printed?\n",
    "\n",
    "        Console.WriteLine(\"123456\");\n",
    "        for( int w = 6; w >= -6; w -= 4) {\n",
    "            string formatStr = \"{0,\" + w + \"}|\";\n",
    "            Console.WriteLine(formatStr, \"here\");\n",
    "        }\n",
    "\n",
    "    Explain, then paste here the screenshot of the results of you testing it in csharprepl or VS Code.\n",
    "\n",
    "10. Even if you want to process every element of a sequence, what would keep\n",
    "    you from using a `foreach` loop?\n",
    "\n",
    "% #. May you legally omit the initialization part of a `for` loop?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6fede1b",
   "metadata": {},
   "source": [
    "## Additional Iteration Review Questions\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"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}
