Skip to main content

Practice · 5 of 5

Debug the range sum

CHALLENGE
Difficulty: beginner+25 XP

sumRange(lo, hi) should return lo + (lo+1) + ... + hi, both ends inclusive. It fails for every call. Trace the loop with lo=2, hi=4 (expected 9) to find the flaw, then fix it minimally.

Back to lesson: Practice: Loop rep