orangeduck / BuildYourOwnLisp

Learn C and build your own programming language in under 1000 lines of code!
http://www.buildyourownlisp.com/
Other
2.9k stars 394 forks source link

On description of for loop in Chapter 3 #30

Closed jiyoo closed 10 years ago

jiyoo commented 10 years ago

I am confused about some part in Chapter 3 of this otherwise easy-to-follow book. Chapter 3 has this paragraph:

The second kind of loop is a for loop. Rather than a condition, this loop requires three expressions separated by semicolons ;. These are an initialiser, a condition and an incrementer. The initialiser is performed before the loop starts, the condition is checked at the end of each iteration of the loop, and if false the loop is exited. The incrementer is performed before the next iteration of the loop.

Aren't things swapped around in the last sentence? I think the following sentence might be the right one

the condition is checked before each iteration of the loop, and if false the loop is exited. The incrementer is performed at the end of each iteration of the loop.

orangeduck commented 10 years ago

Yes I think you are correct. Thanks for pointing this out.

While a loop is running, being at the end of one iteration or the beginning of the next is the same thing. But there is a distinction for the first iteration of a loop, which wont happen if the condition is false, and where the incremented is not performed.

So you are correct. I'll make this change.

orangeduck commented 10 years ago

Should be fixed in 8722e4a5cc43d3ac6d4e29d2d83e4d06f5f944f5. Thanks!