Not being a CS major, my way into code and the ways of programming has been iterative and, well, circular. From what I’ve gathered, this is not only not unusual it is instead “the way it is.” To this point, in the introduction to EJ, Haverbeke presents a primitive program that finds the sum of the numbers from 1 to 10. In my own words, this is how the program works:
- Assign the number 0 to location 0. (This is our sum.)
- Assign the number 1 to location 1. (This is our count.)
- Assign the value of location 1 to location 2. (This is our test.)
- Subtract 11 (the upper limit of the range + 1, so if we were looking for the sum of the numbers between 1 and 100, this would be 101) from the value of location 2. (This establishes whether or not we’ve reached our upper limit.)
- If it is true that the value of location 2 is now 0, go to step 9. Otherwise proceed to step 6. (If it is 0, we’ve summed all needed digits and should stop and simply return the value of location 0, or step 9.)
- Add the value of location 1 to location 0. (Our sum-finding action.)
- Add one to the value of location 1. (This advances our count. The sum-finding action should only run as long as the count is less than or equal to our upper limit.)
- Repeat steps 3 through 7 until 5 is true.
- Return value of location 0. (It’s 55.)
Again, not being a CS major – an English major with a Master’s degree, in fact! – wrapping my mind around this very simple program was a bit of an “A-HA” moment. If there is one thing I can say I absolutely enjoy about programming is that feeling of progress; the insight is real, and things you learn make it possible to learn more things in an almost exponential way. Seeing the results of learning to code means feeling the power of programming – until next time!