Hi
I'm using the electronic version so I don't have page numbers to refer to.
In chapter 2, under the section "The for Statement", example "2. Adding Multiple Terms to the for Statement
the output the book says I should get is:
0 1 2 3 4
the output I get is:
0 1 2 3 4 5
I've triple checked the code I'm compiling and I'm sure I haven't entered a typo, and the output I'm getting makes sense to me, here's my reasoning:
at the end of the fifth iteration x=4, y=4
so on the next iteration (sixth) the boolean expression evaluates to true, and x and y are each incremented to 5
boolean expression now evaluates to false, so there is no seventh iteration
at the end of the for loop, printed out is "0 1 2 3 4"
after the for loop you have the print statement that prints out the value of x, which is 5, so you have
"0 1 2 3 4 5"
Where is my logic going wrong? Or have I indeed typed something incorrectly.
Thankye all kindly
I'm using the electronic version so I don't have page numbers to refer to.
In chapter 2, under the section "The for Statement", example "2. Adding Multiple Terms to the for Statement
the output the book says I should get is:
0 1 2 3 4
the output I get is:
0 1 2 3 4 5
I've triple checked the code I'm compiling and I'm sure I haven't entered a typo, and the output I'm getting makes sense to me, here's my reasoning:
at the end of the fifth iteration x=4, y=4
so on the next iteration (sixth) the boolean expression evaluates to true, and x and y are each incremented to 5
boolean expression now evaluates to false, so there is no seventh iteration
at the end of the for loop, printed out is "0 1 2 3 4"
after the for loop you have the print statement that prints out the value of x, which is 5, so you have
"0 1 2 3 4 5"
Where is my logic going wrong? Or have I indeed typed something incorrectly.
Thankye all kindly