Practice Lab 11.4
Practice Lab 11.4 — Sentinel, Counter, and Sequence Loops
Name: Date:
Instructions
Complete the full worksheet with Bash scripts in a disposable directory. Record predictions and output. Use short bounds before long sequences and make sure every loop changes toward termination.
- Build a
carryonloop controlled by user inputY; prompt/read in the body. Test several responses and explain. - Build a
whilecounter from 0 until 10; explain condition and increment. - Build an
untilcounter to 25; compare continuation rules. - Create the weekday guessing loop using a value captured from
date +%a. Explain command substitution and date/locale dependence. - Trace a print-then-increment loop ending at 10 and explain why the last printed value may differ from the condition boundary.
- Write a loop counting by twos from 0 to 20, a countdown from 100 to 0, and a multiply-by-three sequence to 243. Record initial value, test, update, output order.
- Test and verify each final value; explain one off-by-one bug and how to avoid it.
Reflection: How can a loop’s update make its condition eventually false (or true for until)?