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.
- Write a user-controlled
whileloop: initializecarryon=Y, prompt, read a new value inside the loop, continue while it isY, then report exit value. Test two Y responses and a non-Y response; explain each condition check. - Trace a counter loop starting at 0, updating by one, and ending at 10. Explain initialization, condition, update, output order, and termination.
- Write an equivalent
untilcounter loop to 25. Compare truth conditions withwhile. - Capture abbreviated weekday using
date +%a; build a guessing loop that repeats until correct. Record current locale/date and explain why responses vary. - Trace a loop that prints values from 0 toward 10 with output before update. Explain why endpoints depend on statement order.
- 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.
- Reflection: What guards help you avoid an infinite loop?