01How Computers Work (online)

Fully solved problem book

Branch and loop tracing

Set 1 of 4 · 32 worked questions. Predict your result before expanding the solution.

These worked traces are meant to build fluency through controlled variation. If several answers feel identical, try the next difficult value and look for the point where a carry, sign, branch, or selected memory address changes the outcome.

Program execution · Problem 0001

Start a counter at 4; subtract 2 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 4.
  2. One loop iteration subtracts 2 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 2.
  5. After two iterations the counter is 0.
  6. In general, after k iterations the counter is 4 − 2×k.
  7. The loop first stops when k≥4/2.
  8. The smallest whole-number iteration count meeting that requirement is 2.
  9. The final counter equals 4−2×2=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 2 iterations

Program execution · Problem 0002

Start a counter at 7; subtract 3 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 7.
  2. One loop iteration subtracts 3 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 4.
  5. After two iterations the counter is 1.
  6. In general, after k iterations the counter is 7 − 3×k.
  7. The loop first stops when k≥7/3.
  8. The smallest whole-number iteration count meeting that requirement is 3.
  9. The final counter equals 7−3×3=-2.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 3 iterations

Program execution · Problem 0003

Start a counter at 10; subtract 1 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 10.
  2. One loop iteration subtracts 1 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 9.
  5. After two iterations the counter is 8.
  6. In general, after k iterations the counter is 10 − 1×k.
  7. The loop first stops when k≥10/1.
  8. The smallest whole-number iteration count meeting that requirement is 10.
  9. The final counter equals 10−10×1=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 10 iterations

Program execution · Problem 0004

Start a counter at 13; subtract 2 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 13.
  2. One loop iteration subtracts 2 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 11.
  5. After two iterations the counter is 9.
  6. In general, after k iterations the counter is 13 − 2×k.
  7. The loop first stops when k≥13/2.
  8. The smallest whole-number iteration count meeting that requirement is 7.
  9. The final counter equals 13−7×2=-1.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 7 iterations

Program execution · Problem 0005

Start a counter at 16; subtract 3 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 16.
  2. One loop iteration subtracts 3 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 13.
  5. After two iterations the counter is 10.
  6. In general, after k iterations the counter is 16 − 3×k.
  7. The loop first stops when k≥16/3.
  8. The smallest whole-number iteration count meeting that requirement is 6.
  9. The final counter equals 16−6×3=-2.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 6 iterations

Program execution · Problem 0006

Start a counter at 19; subtract 1 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 19.
  2. One loop iteration subtracts 1 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 18.
  5. After two iterations the counter is 17.
  6. In general, after k iterations the counter is 19 − 1×k.
  7. The loop first stops when k≥19/1.
  8. The smallest whole-number iteration count meeting that requirement is 19.
  9. The final counter equals 19−19×1=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 19 iterations

Program execution · Problem 0007

Start a counter at 22; subtract 2 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 22.
  2. One loop iteration subtracts 2 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 20.
  5. After two iterations the counter is 18.
  6. In general, after k iterations the counter is 22 − 2×k.
  7. The loop first stops when k≥22/2.
  8. The smallest whole-number iteration count meeting that requirement is 11.
  9. The final counter equals 22−11×2=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 11 iterations

Program execution · Problem 0008

Start a counter at 25; subtract 3 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 25.
  2. One loop iteration subtracts 3 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 22.
  5. After two iterations the counter is 19.
  6. In general, after k iterations the counter is 25 − 3×k.
  7. The loop first stops when k≥25/3.
  8. The smallest whole-number iteration count meeting that requirement is 9.
  9. The final counter equals 25−9×3=-2.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 9 iterations

Program execution · Problem 0009

Start a counter at 28; subtract 1 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 28.
  2. One loop iteration subtracts 1 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 27.
  5. After two iterations the counter is 26.
  6. In general, after k iterations the counter is 28 − 1×k.
  7. The loop first stops when k≥28/1.
  8. The smallest whole-number iteration count meeting that requirement is 28.
  9. The final counter equals 28−28×1=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 28 iterations

Program execution · Problem 0010

Start a counter at 31; subtract 2 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 31.
  2. One loop iteration subtracts 2 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 29.
  5. After two iterations the counter is 27.
  6. In general, after k iterations the counter is 31 − 2×k.
  7. The loop first stops when k≥31/2.
  8. The smallest whole-number iteration count meeting that requirement is 16.
  9. The final counter equals 31−16×2=-1.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 16 iterations

Program execution · Problem 0011

Start a counter at 34; subtract 3 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 34.
  2. One loop iteration subtracts 3 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 31.
  5. After two iterations the counter is 28.
  6. In general, after k iterations the counter is 34 − 3×k.
  7. The loop first stops when k≥34/3.
  8. The smallest whole-number iteration count meeting that requirement is 12.
  9. The final counter equals 34−12×3=-2.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 12 iterations

Program execution · Problem 0012

Start a counter at 37; subtract 1 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 37.
  2. One loop iteration subtracts 1 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 36.
  5. After two iterations the counter is 35.
  6. In general, after k iterations the counter is 37 − 1×k.
  7. The loop first stops when k≥37/1.
  8. The smallest whole-number iteration count meeting that requirement is 37.
  9. The final counter equals 37−37×1=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 37 iterations

Program execution · Problem 0013

Start a counter at 40; subtract 2 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 40.
  2. One loop iteration subtracts 2 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 38.
  5. After two iterations the counter is 36.
  6. In general, after k iterations the counter is 40 − 2×k.
  7. The loop first stops when k≥40/2.
  8. The smallest whole-number iteration count meeting that requirement is 20.
  9. The final counter equals 40−20×2=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 20 iterations

Program execution · Problem 0014

Start a counter at 43; subtract 3 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 43.
  2. One loop iteration subtracts 3 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 40.
  5. After two iterations the counter is 37.
  6. In general, after k iterations the counter is 43 − 3×k.
  7. The loop first stops when k≥43/3.
  8. The smallest whole-number iteration count meeting that requirement is 15.
  9. The final counter equals 43−15×3=-2.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 15 iterations

Program execution · Problem 0015

Start a counter at 46; subtract 1 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 46.
  2. One loop iteration subtracts 1 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 45.
  5. After two iterations the counter is 44.
  6. In general, after k iterations the counter is 46 − 1×k.
  7. The loop first stops when k≥46/1.
  8. The smallest whole-number iteration count meeting that requirement is 46.
  9. The final counter equals 46−46×1=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 46 iterations

Program execution · Problem 0016

Start a counter at 49; subtract 2 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 49.
  2. One loop iteration subtracts 2 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 47.
  5. After two iterations the counter is 45.
  6. In general, after k iterations the counter is 49 − 2×k.
  7. The loop first stops when k≥49/2.
  8. The smallest whole-number iteration count meeting that requirement is 25.
  9. The final counter equals 49−25×2=-1.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 25 iterations

Program execution · Problem 0017

Start a counter at 52; subtract 3 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 52.
  2. One loop iteration subtracts 3 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 49.
  5. After two iterations the counter is 46.
  6. In general, after k iterations the counter is 52 − 3×k.
  7. The loop first stops when k≥52/3.
  8. The smallest whole-number iteration count meeting that requirement is 18.
  9. The final counter equals 52−18×3=-2.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 18 iterations

Program execution · Problem 0018

Start a counter at 55; subtract 1 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 55.
  2. One loop iteration subtracts 1 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 54.
  5. After two iterations the counter is 53.
  6. In general, after k iterations the counter is 55 − 1×k.
  7. The loop first stops when k≥55/1.
  8. The smallest whole-number iteration count meeting that requirement is 55.
  9. The final counter equals 55−55×1=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 55 iterations

Program execution · Problem 0019

Start a counter at 58; subtract 2 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 58.
  2. One loop iteration subtracts 2 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 56.
  5. After two iterations the counter is 54.
  6. In general, after k iterations the counter is 58 − 2×k.
  7. The loop first stops when k≥58/2.
  8. The smallest whole-number iteration count meeting that requirement is 29.
  9. The final counter equals 58−29×2=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 29 iterations

Program execution · Problem 0020

Start a counter at 61; subtract 3 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 61.
  2. One loop iteration subtracts 3 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 58.
  5. After two iterations the counter is 55.
  6. In general, after k iterations the counter is 61 − 3×k.
  7. The loop first stops when k≥61/3.
  8. The smallest whole-number iteration count meeting that requirement is 21.
  9. The final counter equals 61−21×3=-2.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 21 iterations

Program execution · Problem 0021

Start a counter at 64; subtract 1 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 64.
  2. One loop iteration subtracts 1 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 63.
  5. After two iterations the counter is 62.
  6. In general, after k iterations the counter is 64 − 1×k.
  7. The loop first stops when k≥64/1.
  8. The smallest whole-number iteration count meeting that requirement is 64.
  9. The final counter equals 64−64×1=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 64 iterations

Program execution · Problem 0022

Start a counter at 67; subtract 2 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 67.
  2. One loop iteration subtracts 2 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 65.
  5. After two iterations the counter is 63.
  6. In general, after k iterations the counter is 67 − 2×k.
  7. The loop first stops when k≥67/2.
  8. The smallest whole-number iteration count meeting that requirement is 34.
  9. The final counter equals 67−34×2=-1.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 34 iterations

Program execution · Problem 0023

Start a counter at 70; subtract 3 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 70.
  2. One loop iteration subtracts 3 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 67.
  5. After two iterations the counter is 64.
  6. In general, after k iterations the counter is 70 − 3×k.
  7. The loop first stops when k≥70/3.
  8. The smallest whole-number iteration count meeting that requirement is 24.
  9. The final counter equals 70−24×3=-2.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 24 iterations

Program execution · Problem 0024

Start a counter at 73; subtract 1 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 73.
  2. One loop iteration subtracts 1 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 72.
  5. After two iterations the counter is 71.
  6. In general, after k iterations the counter is 73 − 1×k.
  7. The loop first stops when k≥73/1.
  8. The smallest whole-number iteration count meeting that requirement is 73.
  9. The final counter equals 73−73×1=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 73 iterations

Program execution · Problem 0025

Start a counter at 76; subtract 2 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 76.
  2. One loop iteration subtracts 2 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 74.
  5. After two iterations the counter is 72.
  6. In general, after k iterations the counter is 76 − 2×k.
  7. The loop first stops when k≥76/2.
  8. The smallest whole-number iteration count meeting that requirement is 38.
  9. The final counter equals 76−38×2=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 38 iterations

Program execution · Problem 0026

Start a counter at 79; subtract 3 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 79.
  2. One loop iteration subtracts 3 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 76.
  5. After two iterations the counter is 73.
  6. In general, after k iterations the counter is 79 − 3×k.
  7. The loop first stops when k≥79/3.
  8. The smallest whole-number iteration count meeting that requirement is 27.
  9. The final counter equals 79−27×3=-2.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 27 iterations

Program execution · Problem 0027

Start a counter at 82; subtract 1 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 82.
  2. One loop iteration subtracts 1 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 81.
  5. After two iterations the counter is 80.
  6. In general, after k iterations the counter is 82 − 1×k.
  7. The loop first stops when k≥82/1.
  8. The smallest whole-number iteration count meeting that requirement is 82.
  9. The final counter equals 82−82×1=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 82 iterations

Program execution · Problem 0028

Start a counter at 85; subtract 2 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 85.
  2. One loop iteration subtracts 2 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 83.
  5. After two iterations the counter is 81.
  6. In general, after k iterations the counter is 85 − 2×k.
  7. The loop first stops when k≥85/2.
  8. The smallest whole-number iteration count meeting that requirement is 43.
  9. The final counter equals 85−43×2=-1.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 43 iterations

Program execution · Problem 0029

Start a counter at 88; subtract 3 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 88.
  2. One loop iteration subtracts 3 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 85.
  5. After two iterations the counter is 82.
  6. In general, after k iterations the counter is 88 − 3×k.
  7. The loop first stops when k≥88/3.
  8. The smallest whole-number iteration count meeting that requirement is 30.
  9. The final counter equals 88−30×3=-2.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 30 iterations

Program execution · Problem 0030

Start a counter at 91; subtract 1 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 91.
  2. One loop iteration subtracts 1 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 90.
  5. After two iterations the counter is 89.
  6. In general, after k iterations the counter is 91 − 1×k.
  7. The loop first stops when k≥91/1.
  8. The smallest whole-number iteration count meeting that requirement is 91.
  9. The final counter equals 91−91×1=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 91 iterations

Program execution · Problem 0031

Start a counter at 94; subtract 2 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 94.
  2. One loop iteration subtracts 2 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 92.
  5. After two iterations the counter is 90.
  6. In general, after k iterations the counter is 94 − 2×k.
  7. The loop first stops when k≥94/2.
  8. The smallest whole-number iteration count meeting that requirement is 47.
  9. The final counter equals 94−47×2=0.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 47 iterations

Program execution · Problem 0032

Start a counter at 97; subtract 3 each iteration while it remains >0. How many iterations?

Try it on paper first. The worked answer is hidden below.

Reveal detailed solution →
  1. The program starts with an accumulator/counter containing 97.
  2. One loop iteration subtracts 3 from the counter.
  3. A conditional branch repeats the body only while the counter is greater than zero.
  4. After one iteration the counter is 94.
  5. After two iterations the counter is 91.
  6. In general, after k iterations the counter is 97 − 3×k.
  7. The loop first stops when k≥97/3.
  8. The smallest whole-number iteration count meeting that requirement is 33.
  9. The final counter equals 97−33×3=-2.
  10. The next PC must take the fall-through route instead of the repeat branch.
  11. This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.

Final answer: 33 iterations