Open in TheBrain

Practice Lab 11.9

Practice Lab 11.9 — While, Until, and Sequence Practice

Name: Date:

Instructions

Use the course Bash environment. Write full scripts and explain each. Use trace tables and test modest bounds first; avoid infinite-loop mistakes.

  1. Build the user-controlled Y repeat loop. Show how a new read value is tested on the next pass.
  2. Build a while incrementing counter from 0 through 10; record values at condition, output, update.
  3. Build an until counter through 25; compare truth conditions and termination.
  4. Build the date guessing loop using abbreviated weekday; record date/locale and explain why fixed sample output isn’t expected.
  5. Trace an echo-then-increment loop and explain the last printed value.
  6. Design/run 0-to-20-by-2, 100-to-0 countdown, and tripling-to-243 loops. Explain endpoint choices.
  7. For each loop identify a possible off-by-one or nontermination error and the correction in your own words.

Reflection: Which variable update guarantees progress in each numeric sequence?