Open in TheBrain

Practice Lab 11.12

Practice Lab 11.12 — Full Loop Tracing and Script Practice

Name: Date:

Instructions

Write each program in Bash in a practice area. For each, record initialization, condition, body, update, predicted output, and actual result. Use short traces first.

  1. Write sentinel-driven while loop controlled by Y, with prompt and read in body. Test continuation and termination.
  2. Write and explain counter loop using while from zero toward ten.
  3. Write equivalent until loop to 25. Compare condition truth and stop point.
  4. Write weekday guessing loop based on date +%a; record locale/time assumptions.
  5. Explain output from echoing a value before incrementing. Predict whether boundary is printed.
  6. Write even sequence 0–20, countdown 100–0, and powers of three to 243. Include trace values and terminate safely.
  7. Change one update step deliberately on paper; predict effect on endpoint/termination. Do not run a loop you predict is infinite.
  8. Explain error diagnosis using variable trace and condition check.

Reflection: What information must be in a trace table to debug a loop?