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.
- Write a user-controlled
whileloop that repeats forY; prompt/read inside the loop and report the exit value. Test multiple inputs. - Write a
whilecounter from 0 to 10 and anuntilcounter from 0 to 25. Compare condition polarity and trace both. - Build a weekday guessing loop using
date +%a; record locale/date and explain variability. - Write and compare print-before-update and update-before-print counter versions. Describe which endpoints appear.
- Create a step-by-two sequence from 0 to 20 and a countdown 20 to 0 by twos. Trace first, middle, last iterations.
- Create multiplication-by-three sequence ending at 243; state start, condition, update, output position.
- Explain how to detect a missing/wrong update and avoid infinite loops.
Reflection: How did changing the step size affect the stop condition?