Question about page 307-308: Chapter 4.10, Exercises 4-5 #89
Closed
MetallicCrimson
started this conversation in
General
Replies: 1 comment
-
|
Yes you are right, I think it should be in the Errata. I'll fix these where the table has an additional row with iteration number to clarify everything. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Ex. 4 has a solution in the Appendix (obviously the same as here), and ex. 5 follows directly.
However, I think the book is giving inconsistent information.
Consider this section from a bit earlier:

Here, the trace table is collecting the values of
xandiafter a whole iteration has been completed - and because aforloop is just syntactic sugar for awhileloop (which includesi := i + 1), technically the value ofiis already one more. (And it ends withi = 5, which makes sense, since that's the point the execution will break out of the loop.)This behavior is not reflected in the Appendix solution, which lists the values of
ias they are at the start of each iteration. This conflicts the fact about the syntactic sugar. Sure, it matches the iteration number, but that can be (and is) different than the value ofi.So going by Example 4.10.3, the correct trace table for Ex. 4 would be:
(And similarly for ex. 5 too.)
This doesn't matter much, since (ideally) an iterator variable in a
forloop isn't used for anything else, but technically makes the (book's) solution incorrect. (The fact that the example has theiline at the bottom and the exercise has it at the top shouldn't modify the values of the table.)This is not listed in the Errata. Do you think it's an issue, or is it fine to leave it this way? Or is my reasoning incorrect?
Beta Was this translation helpful? Give feedback.
All reactions