Fully solved problem book
Branch and loop tracing
Set 2 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 0033
Start a counter at 100; 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 100.
- 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 99.
- After two iterations the counter is 98.
- In general, after k iterations the counter is 100 − 1×k.
- The loop first stops when k≥100/1.
- The smallest whole-number iteration count meeting that requirement is 100.
- The final counter equals 100−100×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: 100 iterations
Program execution · Problem 0034
Start a counter at 103; 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 103.
- 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 101.
- After two iterations the counter is 99.
- In general, after k iterations the counter is 103 − 2×k.
- The loop first stops when k≥103/2.
- The smallest whole-number iteration count meeting that requirement is 52.
- The final counter equals 103−52×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: 52 iterations
Program execution · Problem 0035
Start a counter at 106; 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 106.
- 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 103.
- After two iterations the counter is 100.
- In general, after k iterations the counter is 106 − 3×k.
- The loop first stops when k≥106/3.
- The smallest whole-number iteration count meeting that requirement is 36.
- The final counter equals 106−36×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: 36 iterations
Program execution · Problem 0036
Start a counter at 109; 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 109.
- 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 108.
- After two iterations the counter is 107.
- In general, after k iterations the counter is 109 − 1×k.
- The loop first stops when k≥109/1.
- The smallest whole-number iteration count meeting that requirement is 109.
- The final counter equals 109−109×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: 109 iterations
Program execution · Problem 0037
Start a counter at 112; 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 112.
- 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 110.
- After two iterations the counter is 108.
- In general, after k iterations the counter is 112 − 2×k.
- The loop first stops when k≥112/2.
- The smallest whole-number iteration count meeting that requirement is 56.
- The final counter equals 112−56×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: 56 iterations
Program execution · Problem 0038
Start a counter at 115; 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 115.
- 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 112.
- After two iterations the counter is 109.
- In general, after k iterations the counter is 115 − 3×k.
- The loop first stops when k≥115/3.
- The smallest whole-number iteration count meeting that requirement is 39.
- The final counter equals 115−39×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: 39 iterations
Program execution · Problem 0039
Start a counter at 118; 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 118.
- 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 117.
- After two iterations the counter is 116.
- In general, after k iterations the counter is 118 − 1×k.
- The loop first stops when k≥118/1.
- The smallest whole-number iteration count meeting that requirement is 118.
- The final counter equals 118−118×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: 118 iterations
Program execution · Problem 0040
Start a counter at 121; 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 121.
- 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 119.
- After two iterations the counter is 117.
- In general, after k iterations the counter is 121 − 2×k.
- The loop first stops when k≥121/2.
- The smallest whole-number iteration count meeting that requirement is 61.
- The final counter equals 121−61×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: 61 iterations
Program execution · Problem 0041
Start a counter at 124; 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 124.
- 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 121.
- After two iterations the counter is 118.
- In general, after k iterations the counter is 124 − 3×k.
- The loop first stops when k≥124/3.
- The smallest whole-number iteration count meeting that requirement is 42.
- The final counter equals 124−42×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: 42 iterations
Program execution · Problem 0042
Start a counter at 127; 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 127.
- 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 126.
- After two iterations the counter is 125.
- In general, after k iterations the counter is 127 − 1×k.
- The loop first stops when k≥127/1.
- The smallest whole-number iteration count meeting that requirement is 127.
- The final counter equals 127−127×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: 127 iterations
Program execution · Problem 0043
Start a counter at 130; 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 130.
- 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 128.
- After two iterations the counter is 126.
- In general, after k iterations the counter is 130 − 2×k.
- The loop first stops when k≥130/2.
- The smallest whole-number iteration count meeting that requirement is 65.
- The final counter equals 130−65×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: 65 iterations
Program execution · Problem 0044
Start a counter at 133; 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 133.
- 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 130.
- After two iterations the counter is 127.
- In general, after k iterations the counter is 133 − 3×k.
- The loop first stops when k≥133/3.
- The smallest whole-number iteration count meeting that requirement is 45.
- The final counter equals 133−45×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: 45 iterations
Program execution · Problem 0045
Start a counter at 136; 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 136.
- 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 135.
- After two iterations the counter is 134.
- In general, after k iterations the counter is 136 − 1×k.
- The loop first stops when k≥136/1.
- The smallest whole-number iteration count meeting that requirement is 136.
- The final counter equals 136−136×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: 136 iterations
Program execution · Problem 0046
Start a counter at 139; 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 139.
- 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 137.
- After two iterations the counter is 135.
- In general, after k iterations the counter is 139 − 2×k.
- The loop first stops when k≥139/2.
- The smallest whole-number iteration count meeting that requirement is 70.
- The final counter equals 139−70×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: 70 iterations
Program execution · Problem 0047
Start a counter at 142; 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 142.
- 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 139.
- After two iterations the counter is 136.
- In general, after k iterations the counter is 142 − 3×k.
- The loop first stops when k≥142/3.
- The smallest whole-number iteration count meeting that requirement is 48.
- The final counter equals 142−48×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: 48 iterations
Program execution · Problem 0048
Start a counter at 145; 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 145.
- 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 144.
- After two iterations the counter is 143.
- In general, after k iterations the counter is 145 − 1×k.
- The loop first stops when k≥145/1.
- The smallest whole-number iteration count meeting that requirement is 145.
- The final counter equals 145−145×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: 145 iterations
Program execution · Problem 0049
Start a counter at 148; 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 148.
- 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 146.
- After two iterations the counter is 144.
- In general, after k iterations the counter is 148 − 2×k.
- The loop first stops when k≥148/2.
- The smallest whole-number iteration count meeting that requirement is 74.
- The final counter equals 148−74×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: 74 iterations
Program execution · Problem 0050
Start a counter at 151; 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 151.
- 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 148.
- After two iterations the counter is 145.
- In general, after k iterations the counter is 151 − 3×k.
- The loop first stops when k≥151/3.
- The smallest whole-number iteration count meeting that requirement is 51.
- The final counter equals 151−51×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: 51 iterations
Program execution · Problem 0051
Start a counter at 154; 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 154.
- 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 153.
- After two iterations the counter is 152.
- In general, after k iterations the counter is 154 − 1×k.
- The loop first stops when k≥154/1.
- The smallest whole-number iteration count meeting that requirement is 154.
- The final counter equals 154−154×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: 154 iterations
Program execution · Problem 0052
Start a counter at 157; 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 157.
- 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 155.
- After two iterations the counter is 153.
- In general, after k iterations the counter is 157 − 2×k.
- The loop first stops when k≥157/2.
- The smallest whole-number iteration count meeting that requirement is 79.
- The final counter equals 157−79×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: 79 iterations
Program execution · Problem 0053
Start a counter at 160; 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 160.
- 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 157.
- After two iterations the counter is 154.
- In general, after k iterations the counter is 160 − 3×k.
- The loop first stops when k≥160/3.
- The smallest whole-number iteration count meeting that requirement is 54.
- The final counter equals 160−54×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: 54 iterations
Program execution · Problem 0054
Start a counter at 163; 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 163.
- 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 162.
- After two iterations the counter is 161.
- In general, after k iterations the counter is 163 − 1×k.
- The loop first stops when k≥163/1.
- The smallest whole-number iteration count meeting that requirement is 163.
- The final counter equals 163−163×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: 163 iterations
Program execution · Problem 0055
Start a counter at 166; 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 166.
- 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 164.
- After two iterations the counter is 162.
- In general, after k iterations the counter is 166 − 2×k.
- The loop first stops when k≥166/2.
- The smallest whole-number iteration count meeting that requirement is 83.
- The final counter equals 166−83×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: 83 iterations
Program execution · Problem 0056
Start a counter at 169; 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 169.
- 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 166.
- After two iterations the counter is 163.
- In general, after k iterations the counter is 169 − 3×k.
- The loop first stops when k≥169/3.
- The smallest whole-number iteration count meeting that requirement is 57.
- The final counter equals 169−57×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: 57 iterations
Program execution · Problem 0057
Start a counter at 172; 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 172.
- 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 171.
- After two iterations the counter is 170.
- In general, after k iterations the counter is 172 − 1×k.
- The loop first stops when k≥172/1.
- The smallest whole-number iteration count meeting that requirement is 172.
- The final counter equals 172−172×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: 172 iterations
Program execution · Problem 0058
Start a counter at 175; 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 175.
- 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 173.
- After two iterations the counter is 171.
- In general, after k iterations the counter is 175 − 2×k.
- The loop first stops when k≥175/2.
- The smallest whole-number iteration count meeting that requirement is 88.
- The final counter equals 175−88×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: 88 iterations
Program execution · Problem 0059
Start a counter at 178; 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 178.
- 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 175.
- After two iterations the counter is 172.
- In general, after k iterations the counter is 178 − 3×k.
- The loop first stops when k≥178/3.
- The smallest whole-number iteration count meeting that requirement is 60.
- The final counter equals 178−60×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: 60 iterations
Program execution · Problem 0060
Start a counter at 181; 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 181.
- 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 180.
- After two iterations the counter is 179.
- In general, after k iterations the counter is 181 − 1×k.
- The loop first stops when k≥181/1.
- The smallest whole-number iteration count meeting that requirement is 181.
- The final counter equals 181−181×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: 181 iterations
Program execution · Problem 0061
Start a counter at 184; 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 184.
- 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 182.
- After two iterations the counter is 180.
- In general, after k iterations the counter is 184 − 2×k.
- The loop first stops when k≥184/2.
- The smallest whole-number iteration count meeting that requirement is 92.
- The final counter equals 184−92×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: 92 iterations
Program execution · Problem 0062
Start a counter at 187; 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 187.
- 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 184.
- After two iterations the counter is 181.
- In general, after k iterations the counter is 187 − 3×k.
- The loop first stops when k≥187/3.
- The smallest whole-number iteration count meeting that requirement is 63.
- The final counter equals 187−63×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: 63 iterations
Program execution · Problem 0063
Start a counter at 190; 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 190.
- 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 189.
- After two iterations the counter is 188.
- In general, after k iterations the counter is 190 − 1×k.
- The loop first stops when k≥190/1.
- The smallest whole-number iteration count meeting that requirement is 190.
- The final counter equals 190−190×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: 190 iterations
Program execution · Problem 0064
Start a counter at 193; 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 193.
- 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 191.
- After two iterations the counter is 189.
- In general, after k iterations the counter is 193 − 2×k.
- The loop first stops when k≥193/2.
- The smallest whole-number iteration count meeting that requirement is 97.
- The final counter equals 193−97×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: 97 iterations