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.
- Create a sentinel-controlled loop asking whether to continue. Use
Yas the repeat response; read a new value each pass; explain when test is evaluated. - Create a counter with
whilefrom 0 to 10, adding one per pass. Trace values at test, output, update. - Recreate the counter using
until, ending at 25. Explain the inverse condition logic. - Build a weekday guessing loop using
day=$(date +%a)or course backticks. Prompt/read until correct; explain case/locale/date dependence. - Explain a loop that prints 0 through 9 while the counter reaches 10. Change output/update order on paper and predict effect.
- 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.
- 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?