Fully solved problem book
Branch and loop tracing
Set 4 of 4 · 24 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 0097
Start a counter at 92; 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 92.
- 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 90.
- After two iterations the counter is 88.
- In general, after k iterations the counter is 92 − 2×k.
- The loop first stops when k≥92/2.
- The smallest whole-number iteration count meeting that requirement is 46.
- The final counter equals 92−46×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: 46 iterations
Program execution · Problem 0098
Start a counter at 95; 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 95.
- 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 92.
- After two iterations the counter is 89.
- In general, after k iterations the counter is 95 − 3×k.
- The loop first stops when k≥95/3.
- The smallest whole-number iteration count meeting that requirement is 32.
- The final counter equals 95−32×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: 32 iterations
Program execution · Problem 0099
Start a counter at 98; 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 98.
- 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 97.
- After two iterations the counter is 96.
- In general, after k iterations the counter is 98 − 1×k.
- The loop first stops when k≥98/1.
- The smallest whole-number iteration count meeting that requirement is 98.
- The final counter equals 98−98×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: 98 iterations
Program execution · Problem 0100
Start a counter at 101; 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 101.
- 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 99.
- After two iterations the counter is 97.
- In general, after k iterations the counter is 101 − 2×k.
- The loop first stops when k≥101/2.
- The smallest whole-number iteration count meeting that requirement is 51.
- The final counter equals 101−51×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: 51 iterations
Program execution · Problem 0101
Start a counter at 104; 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 104.
- 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 101.
- After two iterations the counter is 98.
- In general, after k iterations the counter is 104 − 3×k.
- The loop first stops when k≥104/3.
- The smallest whole-number iteration count meeting that requirement is 35.
- The final counter equals 104−35×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: 35 iterations
Program execution · Problem 0102
Start a counter at 107; 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 107.
- 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 106.
- After two iterations the counter is 105.
- In general, after k iterations the counter is 107 − 1×k.
- The loop first stops when k≥107/1.
- The smallest whole-number iteration count meeting that requirement is 107.
- The final counter equals 107−107×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: 107 iterations
Program execution · Problem 0103
Start a counter at 110; 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 110.
- 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 108.
- After two iterations the counter is 106.
- In general, after k iterations the counter is 110 − 2×k.
- The loop first stops when k≥110/2.
- The smallest whole-number iteration count meeting that requirement is 55.
- The final counter equals 110−55×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: 55 iterations
Program execution · Problem 0104
Start a counter at 113; 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 113.
- 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 110.
- After two iterations the counter is 107.
- In general, after k iterations the counter is 113 − 3×k.
- The loop first stops when k≥113/3.
- The smallest whole-number iteration count meeting that requirement is 38.
- The final counter equals 113−38×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: 38 iterations
Program execution · Problem 0105
Start a counter at 116; 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 116.
- 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 115.
- After two iterations the counter is 114.
- In general, after k iterations the counter is 116 − 1×k.
- The loop first stops when k≥116/1.
- The smallest whole-number iteration count meeting that requirement is 116.
- The final counter equals 116−116×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: 116 iterations
Program execution · Problem 0106
Start a counter at 119; 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 119.
- 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 117.
- After two iterations the counter is 115.
- In general, after k iterations the counter is 119 − 2×k.
- The loop first stops when k≥119/2.
- The smallest whole-number iteration count meeting that requirement is 60.
- The final counter equals 119−60×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: 60 iterations
Program execution · Problem 0107
Start a counter at 122; 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 122.
- 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 119.
- After two iterations the counter is 116.
- In general, after k iterations the counter is 122 − 3×k.
- The loop first stops when k≥122/3.
- The smallest whole-number iteration count meeting that requirement is 41.
- The final counter equals 122−41×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: 41 iterations
Program execution · Problem 0108
Start a counter at 125; 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 125.
- 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 124.
- After two iterations the counter is 123.
- In general, after k iterations the counter is 125 − 1×k.
- The loop first stops when k≥125/1.
- The smallest whole-number iteration count meeting that requirement is 125.
- The final counter equals 125−125×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: 125 iterations
Program execution · Problem 0109
Start a counter at 128; 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 128.
- 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 126.
- After two iterations the counter is 124.
- In general, after k iterations the counter is 128 − 2×k.
- The loop first stops when k≥128/2.
- The smallest whole-number iteration count meeting that requirement is 64.
- The final counter equals 128−64×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: 64 iterations
Program execution · Problem 0110
Start a counter at 131; 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 131.
- 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 128.
- After two iterations the counter is 125.
- In general, after k iterations the counter is 131 − 3×k.
- The loop first stops when k≥131/3.
- The smallest whole-number iteration count meeting that requirement is 44.
- The final counter equals 131−44×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: 44 iterations
Program execution · Problem 0111
Start a counter at 134; 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 134.
- 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 133.
- After two iterations the counter is 132.
- In general, after k iterations the counter is 134 − 1×k.
- The loop first stops when k≥134/1.
- The smallest whole-number iteration count meeting that requirement is 134.
- The final counter equals 134−134×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: 134 iterations
Program execution · Problem 0112
Start a counter at 137; 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 137.
- 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 135.
- After two iterations the counter is 133.
- In general, after k iterations the counter is 137 − 2×k.
- The loop first stops when k≥137/2.
- The smallest whole-number iteration count meeting that requirement is 69.
- The final counter equals 137−69×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: 69 iterations
Program execution · Problem 0113
Start a counter at 140; 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 140.
- 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 137.
- After two iterations the counter is 134.
- In general, after k iterations the counter is 140 − 3×k.
- The loop first stops when k≥140/3.
- The smallest whole-number iteration count meeting that requirement is 47.
- The final counter equals 140−47×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: 47 iterations
Program execution · Problem 0114
Start a counter at 143; 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 143.
- 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 142.
- After two iterations the counter is 141.
- In general, after k iterations the counter is 143 − 1×k.
- The loop first stops when k≥143/1.
- The smallest whole-number iteration count meeting that requirement is 143.
- The final counter equals 143−143×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: 143 iterations
Program execution · Problem 0115
Start a counter at 146; 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 146.
- 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 144.
- After two iterations the counter is 142.
- In general, after k iterations the counter is 146 − 2×k.
- The loop first stops when k≥146/2.
- The smallest whole-number iteration count meeting that requirement is 73.
- The final counter equals 146−73×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: 73 iterations
Program execution · Problem 0116
Start a counter at 149; 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 149.
- 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 146.
- After two iterations the counter is 143.
- In general, after k iterations the counter is 149 − 3×k.
- The loop first stops when k≥149/3.
- The smallest whole-number iteration count meeting that requirement is 50.
- The final counter equals 149−50×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: 50 iterations
Program execution · Problem 0117
Start a counter at 152; 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 152.
- 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 151.
- After two iterations the counter is 150.
- In general, after k iterations the counter is 152 − 1×k.
- The loop first stops when k≥152/1.
- The smallest whole-number iteration count meeting that requirement is 152.
- The final counter equals 152−152×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: 152 iterations
Program execution · Problem 0118
Start a counter at 155; 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 155.
- 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 153.
- After two iterations the counter is 151.
- In general, after k iterations the counter is 155 − 2×k.
- The loop first stops when k≥155/2.
- The smallest whole-number iteration count meeting that requirement is 78.
- The final counter equals 155−78×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: 78 iterations
Program execution · Problem 0119
Start a counter at 158; 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 158.
- 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 155.
- After two iterations the counter is 152.
- In general, after k iterations the counter is 158 − 3×k.
- The loop first stops when k≥158/3.
- The smallest whole-number iteration count meeting that requirement is 53.
- The final counter equals 158−53×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: 53 iterations
Program execution · Problem 0120
Start a counter at 161; 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 161.
- 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 160.
- After two iterations the counter is 159.
- In general, after k iterations the counter is 161 − 1×k.
- The loop first stops when k≥161/1.
- The smallest whole-number iteration count meeting that requirement is 161.
- The final counter equals 161−161×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: 161 iterations