Practice Lab 11.6
Practice Lab 11.6 — Loop Tracing and Termination
Name: Date:
Instructions
Complete all tasks using a safe Bash shell. Record traces and output. Verify progress and termination; do not repeatedly run a loop whose update is missing or incorrect.
- Write a user-controlled
whileloop with sentinelY. Prompt and read each pass; test valid and stopping inputs. - Trace and run counter
whileloop from 0 to 10; record condition, output, and update values. - Write an
untilloop counter ending at 25; explainuntilbehavior versuswhile. - Capture the abbreviated weekday from
date, prompt for guesses, loop until correct. Explain command substitution, date/locale variability, and stopping condition. - Explain why print-before-increment loop displays values below its test boundary.
- Design three loops: increment by 2 from 0 through 20; decrement from 100 through 0; multiply by 3 from an appropriate start until 243. Record a trace for each.
- For one loop, deliberately describe (do not run indefinitely) what happens if update is omitted. State safe debugging steps.
Reflection: What are the four parts you check when a numeric loop has an off-by-one error?