Open in TheBrain

Practice Lab 11.11

Practice Lab 11.11 — Expanded Loop Boundary Practice

Name: Date:

Instructions

Use Bash and the class shell. Complete the full worksheet; practice each loop pattern and record traces. Do not execute a loop that you suspect will not terminate.

  1. Create the Y sentinel loop. Test uppercase Y, then a stopping value; explain comparison and next read.
  2. Write a counter while to 10 and an until to 25. Trace first/last tests and compare conditions.
  3. Capture current weekday with date +%a; create guessing loop. Explain command substitution and how locale/capitalization may affect matching.
  4. Trace print-before-update loop to 10. Then write a second version with update before output and compare predicted first/last values.
  5. Design 0–20 by 2; test a start value that would skip the endpoint and explain why your condition must match step size.
  6. Design 100–0 countdown; ensure zero is included. Trace first, middle, last iteration.
  7. Design multiplication-by-three sequence ending at 243; identify starting value and exact termination criterion.
  8. Explain safe debugging of bad conditions/updates, and compare while and until.

Reflection: Which boundary case helped reveal an off-by-one issue?