Practice Lab 11 Hub
Practice Lab 11 — Provisional Hub and Learning Analysis
Status: Provisional. This hub is based on the Lab 11 worksheet. Instructor-solution review is pending; exact expected interpretations and any corrections to the prompt should be confirmed when the solution is available.
Source lab
Based on the instructor worksheet in Operating Systems Management, Lab, 11. The source lab is linked as a child of this hub. This hub summarizes the prompt and likely learning goals; it is not a completed solution or answer key.
Overview
Lab 11 builds on shell variables and Lab 10’s loop concepts by introducing while and until loops, user-controlled repetition, numeric counters, command substitution, and loop design. Learners trace supplied scripts, compare two loop forms, use a date-derived value in a guessing loop, and write scripts for counting by twos, counting down, and repeatedly multiplying by three.
The progression moves from understanding when a loop continues, to updating a value so the loop eventually terminates, to designing the initialization, condition, update, and output order for a desired sequence. Correct spacing, quoting, integer comparisons, and update placement matter. The source asks learners to type code in vi rather than paste it, specifically to avoid quote-character problems.
What this lab appears to teach
A while loop repeats its body while its test condition is true; an until loop repeats while its test condition is false and stops when the condition becomes true. Both require a condition that can eventually change, usually because a variable is updated inside the loop. A missing or incorrect update can create an infinite loop.
The first example uses user input as the condition-changing value; another uses a numeric variable incremented each iteration. The later exercises extend this reasoning to other sequences: counting by a fixed step, decrementing to a boundary, and multiplying through a sequence until a target is reached or passed. These tasks require deliberate decisions about the starting value, comparison operator, update expression, output placement, and termination boundary.
Observable learning objectives
Based on the prompt, learners should be able to:
- Trace a user-controlled
whileloop and explain how input changes the next condition test. - Explain the roles of initialization, condition, loop body, update, and loop termination.
- Describe the difference between
whileanduntilin terms of the truth of their stopping/continuing conditions. - Use a counter variable that changes each iteration and reason about when the loop ends.
- Explain how command substitution can store the output of a command, such as a formatted weekday, in a variable.
- Trace a guessing loop that prompts again until the input matches a stored value.
- Predict how statement order (display before or after update) affects the first and last displayed values.
- Design a finite loop for a sequence that advances by a fixed step, decreases to a boundary, or grows by repeated multiplication.
- Choose a condition and update that reach the intended endpoint without an unintended extra iteration or an infinite loop.
- Record output from the learner’s environment and explain any system-dependent values.
Concepts and skills, in sequence
1. User-controlled repetition
The first example initializes a control variable, tests it against a sentinel value, displays a message, reads a replacement value, and repeats or exits based on that new value. This introduces a sentinel-controlled loop: user input controls termination. The learner should track the value before and after each read and understand that the condition is checked again at the top of the next iteration.
2. Counter-controlled while loop
The next example initializes a numeric counter, tests whether it has reached a boundary, increments it, and displays it. Learners explain each line and observe how the variable update guarantees eventual termination. The order of the increment and output affects whether the starting value appears in the output; make this a prediction question rather than an assumed detail.
3. Compare while and until
The paired counter examples use different loop forms to reach a stopping point. The conceptual comparison is the condition polarity: while continues while its condition is true, whereas until continues until its condition becomes true. The bodies may otherwise perform similar work. Confirm the instructor’s expected explanation and notation when the solution is available.
4. Date-driven guessing loop
A date-formatting command supplies an abbreviated weekday, captured into a variable using command substitution. The script prompts for a guess, reads input, and repeats the prompt while the guess differs from the stored day. This combines command substitution, variable comparison, user input, and loop control. The correct response depends on the actual date and the format used, so expected output is time-dependent. The worksheet’s weekday prompt gives abbreviations; spelling/case and locale behavior should be made explicit in a finalized practice version.
5. Output order and loop tracing
A short example displays the counter and then increments it. Learners explain the observed sequence and how ordering statements changes what appears. This is a direct way to teach trace tables: record the counter value at the condition check, at output, and after the update for each iteration.
6. Design a step-counting loop
The learner writes a script that advances from a stated start toward an endpoint by twos. The design needs a start value, a condition that permits the desired values, a consistent update by the step size, and output in the intended position. Verify whether the endpoint is included and ensure the update cannot skip past a condition that would otherwise be required for termination.
7. Design a countdown loop
The learner writes a sequence from 100 down to 0. This reverses the direction of the update and requires a boundary condition that includes the intended final value. Explicitly plan whether output occurs before or after decrementing and how the loop stops at zero.
8. Repeated multiplication loop
The final exercise repeatedly multiplies a value by three toward 243. Learners must choose a suitable initial value, update rule, comparison, and output location. The phrase “count to 243 multiplying by 3” should be clarified in the practice design: does the sequence begin at 1 or another value, and should it stop exactly at or include 243? The prompt’s likely intent is a geometric sequence, but exact expected setup should be confirmed.
Prerequisites and dependencies
- Familiarity with shell variables, comparisons, command substitution,
expr, and quote syntax from Lab 8. - Basic shell script creation and execution using the editor and method expected by the course.
- Understanding of
while/forloop structure and loop-body delimiters from prior labs. - A Bash-compatible or otherwise specified shell environment; test the worksheet’s syntax in the assigned shell.
- A terminal for interactive
readinput and date output. - A safe way to stop a mistaken infinite loop and a disposable practice session.
Likely trouble spots and questions to verify
- Condition polarity: Learners may assume
whileanduntilhave identical continuation rules. Use a truth-value trace to distinguish them. - Loop progress and infinite loops: Every counter loop needs an update that moves toward a condition that eventually ends the loop. Test small ranges before running long sequences.
- Off-by-one errors: Starting value, condition boundary, update order, and output order determine whether zero, the start, or endpoint is printed. Have learners trace values before execution.
- Spacing and syntax: Shell test brackets require appropriate token separation; the worksheet’s typography and spacing may not copy correctly from a formatted document.
- Integer comparison operators: The worksheet uses test operators such as
-neand-eq; use the correct operator form for the shell test rather than mathematical glyphs or Unicode dashes. exprsyntax: Arithmetic operands need the expected separation; multiplication symbols may need escaping so the shell does not treat them as a filename wildcard. A missing space can produce concatenated text rather than arithmetic.- User input and sentinel: The user-controlled loop depends on entering the exact sentinel value, including case. Clarify what happens for blank or unexpected input.
- Date-dependent guessing: The weekday changes daily and can vary with locale/time zone. Do not use a fixed sample answer; generate or discuss the expected value for the current environment.
- Target for multiplication: Clarify the initial value and whether endpoint inclusion is required before scoring a solution.
- Prompt says “count” broadly: Fixed-step and multiplicative sequences are different patterns; distinguish a numerical counter from an iterative sequence.
- Smart quotes: Replace curly quotation marks and en dashes from the document with valid shell characters when typing code. Follow the instructor’s warning to type rather than paste if the editor changes punctuation.
How learning should be demonstrated
Evidence should include prediction, trace, execution, and explanation:
- Trace variable values through each condition check, input, output, and update.
- Explain why the first loop repeats or exits after each user response.
- Compare
whileanduntilby evaluating their conditions, not only by quoting definitions. - Predict whether the first value and endpoint will be printed before running a counter loop.
- For each custom sequence, identify initialization, condition, update, output, and termination boundary.
- Test the smallest useful range first, then verify the final sequence and that the loop terminates.
- Explain how the weekday value is produced and why it changes with date and locale.
- Record any errors and diagnose spacing, quoting, comparison, or update issues rather than silently copying a corrected script.
Practice-design recommendation (not exercises yet)
Build practice from traceable, small loops. Start with a hand-trace table for the user-controlled loop, then a short counter loop and an equivalent until version. For custom sequences, ask learners to fill in start value, condition, update, output position, and expected final value before writing code. Run small ranges first, and include a clear recovery instruction for stopping an unintended infinite loop in the designated terminal.
Use ASCII quotes and hyphens in code examples, and specify the shell. Make the date-guessing exercise explicitly locale-aware or use an instructor-provided expected value. Clarify whether endpoints are inclusive in all sequence tasks, especially repeated multiplication. Leave room for code, expected output, actual output, a trace/explanation, and a reflection.
Pending solution review
- Instructor’s expected output/interpretation for each sample loop, including whether endpoints are included.
- The intended initial value and endpoint behavior for the repeated-multiplication task.
- Expected treatment of the weekday abbreviation, case, and locale.
- Whether use of
expris required or only demonstrated, and any shell-specific syntax requirements. - Any corrections to the prompt’s quote/spacing examples.
Scope status
This hub is a prompt-based first draft. No new practice exercises or answer key have been created. Revise the pending points after the instructor solution is available.