04 Try it yourself Interactive
Press Next to move i one cell to the right. The amber cell is the one being read on this step; emerald marks what the accumulator has already taken in — in max mode that is the single cell best came from, so on a step where best changes the new home is still amber and only turns emerald on the next press. Switch tabs and the shape of the walk is the same, but the seed, the start index and the body all change together: best is seeded from a[0] and starts at i = 1, sum is seeded with 0 and starts at i = 0. The interesting step is the second-to-last one: i reaches n, the guard refuses, and a[n] is never read.