Open in TheBrain

Practice Lab 11.3

Practice Lab 11.3 — Complete Loop Design Worksheet

Name: Date:

Instructions

Use Bash in a safe terminal. For every loop, list initialization, condition, body, update, and termination. Start with small values, then record actual output.

  1. Write and run a user-controlled while loop that repeats when input is Y, prompts inside the loop, and ends for any other response. Explain sentinel behavior.
  2. Write a while counter from 0 to 10. Show a trace table of value at test/output/update.
  3. Write an until counter from 0 to 25. Compare with the while version.
  4. Make a weekday guessing program using date +%a, read, and a loop until correct. Record locale and current abbreviated weekday; explain variability.
  5. Analyze a loop that outputs counter before incrementing to 10. State what appears and why output order matters.
  6. Design and run three sequences: even numbers 0–20, countdown 100–0, and powers of three ending at 243. Include endpoint reasoning and ensure termination.
  7. Explain how to detect a loop that cannot terminate and what to check before execution.

Reflection: What is the condition polarity difference between while and until?