Open in TheBrain

Practice Lab 11.1

Practice Lab 11.1 — Complete while and until Lab

Name: Date:

Instructions

Use Bash and a practice directory. Record script, trace table, output, and explanation. Test small loops first; an incorrect condition/update can run indefinitely. Use ASCII quotes and comparison operators.

  1. Write a user-controlled while loop: initialize carryon=Y, prompt, read a new value inside the loop, continue while it is Y, then report exit value. Test two Y responses and a non-Y response; explain each condition check.
  2. Trace a counter loop starting at 0, updating by one, and ending at 10. Explain initialization, condition, update, output order, and termination.
  3. Write an equivalent until counter loop to 25. Compare truth conditions with while.
  4. Capture abbreviated weekday using date +%a; build a guessing loop that repeats until correct. Record current locale/date and explain why responses vary.
  5. Trace a loop that prints values from 0 toward 10 with output before update. Explain why endpoints depend on statement order.
  6. Write loops for counting 0 to 20 by twos, down from 100 to 0, and multiplying by 3 until reaching 243. For each, state start, condition, update, output position, termination check. Test safely.
  7. Reflection: What guards help you avoid an infinite loop?