Need help understanding why code works only a certain way

I did no planning before playing with the Arduino. This was the simpliest example of a time diagram I saw online and should work for this sketch.