Trace an iterative even sum

Scenario. A procedure adds all even whole numbers from 1 through a supplied upper bound, including the bound when it is even.

Inputs. number, a non-negative whole number. Other values are invalid.

Rules and notation. A number is even when division by 2 leaves remainder 0. For number = 0, the range is empty and the sum is 0.

Assumptions. Arithmetic does not overflow for the supplied input.

Listing 1 makes the structure for trace an iterative even sum explicit so you can identify its required fields and boundaries.

Listing 1: Structured example of trace an iterative even sum.
IF number is not a non-negative whole number
    OUTPUT Invalid input
    STOP
END IF

SET total TO 0
SET i TO 1

WHILE i <= number
    IF i is even
        SET total TO total + i
    END IF
    SET i TO i + 1
END WHILE

OUTPUT total

Deliverable. Trace i and total for number = 4. Give expected outputs for 0, 1, 2, and 4, and state why the loop terminates.

Success criteria. The trace includes the boundary value 4, adds only the even values in the range, returns 0 for an empty range, and identifies a progress measure that decreases on every iteration.

Record total after the possible addition and then increase i, even when i is odd.