Fully solved problem book
Branch and loop tracing
Set 3 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 0065
Start a counter at 196; 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 →
- The program starts with an accumulator/counter containing 196.
- One loop iteration subtracts 3 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 193.
- After two iterations the counter is 190.
- In general, after k iterations the counter is 196 − 3×k.
- The loop first stops when k≥196/3.
- The smallest whole-number iteration count meeting that requirement is 66.
- The final counter equals 196−66×3=-2.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 66 iterations
Program execution · Problem 0066
Start a counter at 199; 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 →
- The program starts with an accumulator/counter containing 199.
- One loop iteration subtracts 1 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 198.
- After two iterations the counter is 197.
- In general, after k iterations the counter is 199 − 1×k.
- The loop first stops when k≥199/1.
- The smallest whole-number iteration count meeting that requirement is 199.
- The final counter equals 199−199×1=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 199 iterations
Program execution · Problem 0067
Start a counter at 2; 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 →
- The program starts with an accumulator/counter containing 2.
- One loop iteration subtracts 2 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 0.
- After two iterations the counter is -2.
- In general, after k iterations the counter is 2 − 2×k.
- The loop first stops when k≥2/2.
- The smallest whole-number iteration count meeting that requirement is 1.
- The final counter equals 2−1×2=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 1 iterations
Program execution · Problem 0068
Start a counter at 5; 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 →
- The program starts with an accumulator/counter containing 5.
- One loop iteration subtracts 3 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 2.
- After two iterations the counter is -1.
- In general, after k iterations the counter is 5 − 3×k.
- The loop first stops when k≥5/3.
- The smallest whole-number iteration count meeting that requirement is 2.
- The final counter equals 5−2×3=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- 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 0069
Start a counter at 8; 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 →
- The program starts with an accumulator/counter containing 8.
- One loop iteration subtracts 1 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 7.
- After two iterations the counter is 6.
- In general, after k iterations the counter is 8 − 1×k.
- The loop first stops when k≥8/1.
- The smallest whole-number iteration count meeting that requirement is 8.
- The final counter equals 8−8×1=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 8 iterations
Program execution · Problem 0070
Start a counter at 11; 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 →
- The program starts with an accumulator/counter containing 11.
- One loop iteration subtracts 2 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 9.
- After two iterations the counter is 7.
- In general, after k iterations the counter is 11 − 2×k.
- The loop first stops when k≥11/2.
- The smallest whole-number iteration count meeting that requirement is 6.
- The final counter equals 11−6×2=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- 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 0071
Start a counter at 14; 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 →
- The program starts with an accumulator/counter containing 14.
- One loop iteration subtracts 3 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 11.
- After two iterations the counter is 8.
- In general, after k iterations the counter is 14 − 3×k.
- The loop first stops when k≥14/3.
- The smallest whole-number iteration count meeting that requirement is 5.
- The final counter equals 14−5×3=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 5 iterations
Program execution · Problem 0072
Start a counter at 17; 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 →
- The program starts with an accumulator/counter containing 17.
- One loop iteration subtracts 1 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 16.
- After two iterations the counter is 15.
- In general, after k iterations the counter is 17 − 1×k.
- The loop first stops when k≥17/1.
- The smallest whole-number iteration count meeting that requirement is 17.
- The final counter equals 17−17×1=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 17 iterations
Program execution · Problem 0073
Start a counter at 20; 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 →
- The program starts with an accumulator/counter containing 20.
- One loop iteration subtracts 2 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 18.
- After two iterations the counter is 16.
- In general, after k iterations the counter is 20 − 2×k.
- The loop first stops when k≥20/2.
- The smallest whole-number iteration count meeting that requirement is 10.
- The final counter equals 20−10×2=0.
- The next PC must take the fall-through route instead of the repeat branch.
- 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 0074
Start a counter at 23; 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 →
- The program starts with an accumulator/counter containing 23.
- One loop iteration subtracts 3 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 20.
- After two iterations the counter is 17.
- In general, after k iterations the counter is 23 − 3×k.
- The loop first stops when k≥23/3.
- The smallest whole-number iteration count meeting that requirement is 8.
- The final counter equals 23−8×3=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 8 iterations
Program execution · Problem 0075
Start a counter at 26; 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 →
- The program starts with an accumulator/counter containing 26.
- One loop iteration subtracts 1 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 25.
- After two iterations the counter is 24.
- In general, after k iterations the counter is 26 − 1×k.
- The loop first stops when k≥26/1.
- The smallest whole-number iteration count meeting that requirement is 26.
- The final counter equals 26−26×1=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 26 iterations
Program execution · Problem 0076
Start a counter at 29; 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 →
- The program starts with an accumulator/counter containing 29.
- One loop iteration subtracts 2 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 27.
- After two iterations the counter is 25.
- In general, after k iterations the counter is 29 − 2×k.
- The loop first stops when k≥29/2.
- The smallest whole-number iteration count meeting that requirement is 15.
- The final counter equals 29−15×2=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- 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 0077
Start a counter at 32; 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 →
- The program starts with an accumulator/counter containing 32.
- One loop iteration subtracts 3 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 29.
- After two iterations the counter is 26.
- In general, after k iterations the counter is 32 − 3×k.
- The loop first stops when k≥32/3.
- The smallest whole-number iteration count meeting that requirement is 11.
- The final counter equals 32−11×3=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- 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 0078
Start a counter at 35; 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 →
- The program starts with an accumulator/counter containing 35.
- One loop iteration subtracts 1 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 34.
- After two iterations the counter is 33.
- In general, after k iterations the counter is 35 − 1×k.
- The loop first stops when k≥35/1.
- The smallest whole-number iteration count meeting that requirement is 35.
- The final counter equals 35−35×1=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 35 iterations
Program execution · Problem 0079
Start a counter at 38; 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 →
- The program starts with an accumulator/counter containing 38.
- One loop iteration subtracts 2 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 36.
- After two iterations the counter is 34.
- In general, after k iterations the counter is 38 − 2×k.
- The loop first stops when k≥38/2.
- The smallest whole-number iteration count meeting that requirement is 19.
- The final counter equals 38−19×2=0.
- The next PC must take the fall-through route instead of the repeat branch.
- 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 0080
Start a counter at 41; 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 →
- The program starts with an accumulator/counter containing 41.
- One loop iteration subtracts 3 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 38.
- After two iterations the counter is 35.
- In general, after k iterations the counter is 41 − 3×k.
- The loop first stops when k≥41/3.
- The smallest whole-number iteration count meeting that requirement is 14.
- The final counter equals 41−14×3=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 14 iterations
Program execution · Problem 0081
Start a counter at 44; 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 →
- The program starts with an accumulator/counter containing 44.
- One loop iteration subtracts 1 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 43.
- After two iterations the counter is 42.
- In general, after k iterations the counter is 44 − 1×k.
- The loop first stops when k≥44/1.
- The smallest whole-number iteration count meeting that requirement is 44.
- The final counter equals 44−44×1=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 44 iterations
Program execution · Problem 0082
Start a counter at 47; 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 →
- The program starts with an accumulator/counter containing 47.
- One loop iteration subtracts 2 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 45.
- After two iterations the counter is 43.
- In general, after k iterations the counter is 47 − 2×k.
- The loop first stops when k≥47/2.
- The smallest whole-number iteration count meeting that requirement is 24.
- The final counter equals 47−24×2=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- 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 0083
Start a counter at 50; 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 →
- The program starts with an accumulator/counter containing 50.
- One loop iteration subtracts 3 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 47.
- After two iterations the counter is 44.
- In general, after k iterations the counter is 50 − 3×k.
- The loop first stops when k≥50/3.
- The smallest whole-number iteration count meeting that requirement is 17.
- The final counter equals 50−17×3=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 17 iterations
Program execution · Problem 0084
Start a counter at 53; 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 →
- The program starts with an accumulator/counter containing 53.
- One loop iteration subtracts 1 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 52.
- After two iterations the counter is 51.
- In general, after k iterations the counter is 53 − 1×k.
- The loop first stops when k≥53/1.
- The smallest whole-number iteration count meeting that requirement is 53.
- The final counter equals 53−53×1=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 53 iterations
Program execution · Problem 0085
Start a counter at 56; 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 →
- The program starts with an accumulator/counter containing 56.
- One loop iteration subtracts 2 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 54.
- After two iterations the counter is 52.
- In general, after k iterations the counter is 56 − 2×k.
- The loop first stops when k≥56/2.
- The smallest whole-number iteration count meeting that requirement is 28.
- The final counter equals 56−28×2=0.
- The next PC must take the fall-through route instead of the repeat branch.
- 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 0086
Start a counter at 59; 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 →
- The program starts with an accumulator/counter containing 59.
- One loop iteration subtracts 3 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 56.
- After two iterations the counter is 53.
- In general, after k iterations the counter is 59 − 3×k.
- The loop first stops when k≥59/3.
- The smallest whole-number iteration count meeting that requirement is 20.
- The final counter equals 59−20×3=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- 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 0087
Start a counter at 62; 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 →
- The program starts with an accumulator/counter containing 62.
- One loop iteration subtracts 1 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 61.
- After two iterations the counter is 60.
- In general, after k iterations the counter is 62 − 1×k.
- The loop first stops when k≥62/1.
- The smallest whole-number iteration count meeting that requirement is 62.
- The final counter equals 62−62×1=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 62 iterations
Program execution · Problem 0088
Start a counter at 65; 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 →
- The program starts with an accumulator/counter containing 65.
- One loop iteration subtracts 2 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 63.
- After two iterations the counter is 61.
- In general, after k iterations the counter is 65 − 2×k.
- The loop first stops when k≥65/2.
- The smallest whole-number iteration count meeting that requirement is 33.
- The final counter equals 65−33×2=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- 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
Program execution · Problem 0089
Start a counter at 68; 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 →
- The program starts with an accumulator/counter containing 68.
- One loop iteration subtracts 3 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 65.
- After two iterations the counter is 62.
- In general, after k iterations the counter is 68 − 3×k.
- The loop first stops when k≥68/3.
- The smallest whole-number iteration count meeting that requirement is 23.
- The final counter equals 68−23×3=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 23 iterations
Program execution · Problem 0090
Start a counter at 71; 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 →
- The program starts with an accumulator/counter containing 71.
- One loop iteration subtracts 1 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 70.
- After two iterations the counter is 69.
- In general, after k iterations the counter is 71 − 1×k.
- The loop first stops when k≥71/1.
- The smallest whole-number iteration count meeting that requirement is 71.
- The final counter equals 71−71×1=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 71 iterations
Program execution · Problem 0091
Start a counter at 74; 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 →
- The program starts with an accumulator/counter containing 74.
- One loop iteration subtracts 2 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 72.
- After two iterations the counter is 70.
- In general, after k iterations the counter is 74 − 2×k.
- The loop first stops when k≥74/2.
- The smallest whole-number iteration count meeting that requirement is 37.
- The final counter equals 74−37×2=0.
- The next PC must take the fall-through route instead of the repeat branch.
- 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 0092
Start a counter at 77; 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 →
- The program starts with an accumulator/counter containing 77.
- One loop iteration subtracts 3 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 74.
- After two iterations the counter is 71.
- In general, after k iterations the counter is 77 − 3×k.
- The loop first stops when k≥77/3.
- The smallest whole-number iteration count meeting that requirement is 26.
- The final counter equals 77−26×3=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 26 iterations
Program execution · Problem 0093
Start a counter at 80; 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 →
- The program starts with an accumulator/counter containing 80.
- One loop iteration subtracts 1 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 79.
- After two iterations the counter is 78.
- In general, after k iterations the counter is 80 − 1×k.
- The loop first stops when k≥80/1.
- The smallest whole-number iteration count meeting that requirement is 80.
- The final counter equals 80−80×1=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 80 iterations
Program execution · Problem 0094
Start a counter at 83; 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 →
- The program starts with an accumulator/counter containing 83.
- One loop iteration subtracts 2 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 81.
- After two iterations the counter is 79.
- In general, after k iterations the counter is 83 − 2×k.
- The loop first stops when k≥83/2.
- The smallest whole-number iteration count meeting that requirement is 42.
- The final counter equals 83−42×2=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 42 iterations
Program execution · Problem 0095
Start a counter at 86; 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 →
- The program starts with an accumulator/counter containing 86.
- One loop iteration subtracts 3 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 83.
- After two iterations the counter is 80.
- In general, after k iterations the counter is 86 − 3×k.
- The loop first stops when k≥86/3.
- The smallest whole-number iteration count meeting that requirement is 29.
- The final counter equals 86−29×3=-1.
- The next PC must take the fall-through route instead of the repeat branch.
- 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 0096
Start a counter at 89; 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 →
- The program starts with an accumulator/counter containing 89.
- One loop iteration subtracts 1 from the counter.
- A conditional branch repeats the body only while the counter is greater than zero.
- After one iteration the counter is 88.
- After two iterations the counter is 87.
- In general, after k iterations the counter is 89 − 1×k.
- The loop first stops when k≥89/1.
- The smallest whole-number iteration count meeting that requirement is 89.
- The final counter equals 89−89×1=0.
- The next PC must take the fall-through route instead of the repeat branch.
- This example uses a greater-than-zero condition; branch-on-not-equal would have different termination behavior for some step sizes.
Final answer: 89 iterations