Open in TheBrain

Practice Lab 11.4

Practice Lab 11.4 — Sentinel, Counter, and Sequence Loops

Name: Date:

Instructions

Complete the full worksheet with Bash scripts in a disposable directory. Record predictions and output. Use short bounds before long sequences and make sure every loop changes toward termination.

  1. Build a carryon loop controlled by user input Y; prompt/read in the body. Test several responses and explain.
  2. Build a while counter from 0 until 10; explain condition and increment.
  3. Build an until counter to 25; compare continuation rules.
  4. Create the weekday guessing loop using a value captured from date +%a. Explain command substitution and date/locale dependence.
  5. Trace a print-then-increment loop ending at 10 and explain why the last printed value may differ from the condition boundary.
  6. Write a loop counting by twos from 0 to 20, a countdown from 100 to 0, and a multiply-by-three sequence to 243. Record initial value, test, update, output order.
  7. Test and verify each final value; explain one off-by-one bug and how to avoid it.

Reflection: How can a loop’s update make its condition eventually false (or true for until)?