Exercise 5: The Odd-Number Sum That Must Not Loop Forever — Possible Solution ==================================================================== i = 0 total = 0 while i < 99: i += 1 # first, so continue cannot skip it if i % 2 == 0: continue total += i print("sum of the odd numbers from 1 to 99:", total) # If i += 1 were the LAST line of the loop body, then for an even i the # continue would jump back to the top without ever running it. i would # stay even forever and the loop would never end. Example run: sum of the odd numbers from 1 to 99: 2500 WHY THIS WORKS AS AN ANSWER ------------------------------ i starts at 0 and is increased as the very first step of every pass, so by the time the continue runs the counter has already moved on. Even numbers are then skipped and odd ones are added: 1 + 3 + ... + 99 = 2500. In a for loop this trap cannot happen, because for moves on by itself. In a while loop the variable is your responsibility, and a continue that jumps over the update gives an infinite loop. The comment at the bottom describes exactly that broken version; do not run it.