Open in TheBrain

Practice Lab 11.2

Practice Lab 11.2 — Full Conditional Loop Practice

Name: Date:

Instructions

Write scripts in the assigned Bash shell. Predict variable values before running and use short tests first. Record code and output; confirm all loops terminate.

  1. Create a sentinel-controlled loop asking whether to continue. Use Y as the repeat response; read a new value each pass; explain when test is evaluated.
  2. Create a counter with while from 0 to 10, adding one per pass. Trace values at test, output, update.
  3. Recreate the counter using until, ending at 25. Explain the inverse condition logic.
  4. Build a weekday guessing loop using day=$(date +%a) or course backticks. Prompt/read until correct; explain case/locale/date dependence.
  5. Explain a loop that prints 0 through 9 while the counter reaches 10. Change output/update order on paper and predict effect.
  6. Write a count-by-two loop 0–20, countdown 100–0, and geometric sequence multiplying by 3 to 243. For each justify boundary and stopping condition.
  7. Test each script; if it fails to progress, stop it safely and identify which update/condition is wrong.

Reflection: Which trace table helped most with off-by-one errors?