Open in TheBrain

Practice Lab 11.16

Practice Lab 11.16 — Expanded while and until Practice

Name: Date:

Instructions

Use Bash scripts in a safe practice directory. Trace condition, value, output, and update before running. Test short ranges first and stop if a loop does not progress.

  1. Write a user-controlled while loop that repeats for Y; prompt/read inside the loop and report the exit value. Test multiple inputs.
  2. Write a while counter from 0 to 10 and an until counter from 0 to 25. Compare condition polarity and trace both.
  3. Build a weekday guessing loop using date +%a; record locale/date and explain variability.
  4. Write and compare print-before-update and update-before-print counter versions. Describe which endpoints appear.
  5. Create a step-by-two sequence from 0 to 20 and a countdown 20 to 0 by twos. Trace first, middle, last iterations.
  6. Create multiplication-by-three sequence ending at 243; state start, condition, update, output position.
  7. Explain how to detect a missing/wrong update and avoid infinite loops.

Reflection: How did changing the step size affect the stop condition?