Open in TheBrain

Practice Lab 11.6

Practice Lab 11.6 — Loop Tracing and Termination

Name: Date:

Instructions

Complete all tasks using a safe Bash shell. Record traces and output. Verify progress and termination; do not repeatedly run a loop whose update is missing or incorrect.

  1. Write a user-controlled while loop with sentinel Y. Prompt and read each pass; test valid and stopping inputs.
  2. Trace and run counter while loop from 0 to 10; record condition, output, and update values.
  3. Write an until loop counter ending at 25; explain until behavior versus while.
  4. Capture the abbreviated weekday from date, prompt for guesses, loop until correct. Explain command substitution, date/locale variability, and stopping condition.
  5. Explain why print-before-increment loop displays values below its test boundary.
  6. Design three loops: increment by 2 from 0 through 20; decrement from 100 through 0; multiply by 3 from an appropriate start until 243. Record a trace for each.
  7. For one loop, deliberately describe (do not run indefinitely) what happens if update is omitted. State safe debugging steps.

Reflection: What are the four parts you check when a numeric loop has an off-by-one error?