Iterative sum algorithm

Figure 1 represents the iterative sum and shows which values change the accumulator. What will be the output if the input—labeled number—is 4?

graph LR
    accTitle: Iterative sum of even numbers
    accDescr: Starting at one, the algorithm adds even values to the sum, skips odd values, and stops after the supplied number.
    A((Start)) --> B[/number/]
    B --> C[Set sum to 0]
    C --> D[Set i to 1]
    D --> E{"Is i<br>less than or<br>equal to<br>number?"}
    E -- Yes --> F{"Is i<br>an even<br>number?"}
    F -- Yes --> G[Add i<br>to the sum]
    F -- No --> H[Keep sum the same]
    G --> I[Increase i by one]
    E -- No --> J[/sum/]
    H --> I
    I --> E
    J --> K((End))
Figure 1: Flowchart that adds each even whole number from 1 through the supplied number.

Choose the correct output:

  • 4
  • 6
  • 8
  • 10
  • 12