I have the book saying that
and says that this is equivalent to saying
Looks like the book just says that for given x
and y
for (int i = x; i <= y; ++i) Sum += 1;
is similar to
and thus, replacing x = 1
and y = N
,
for (int i = 1; i <= N; ++i) Sum += 1;
is similar to
This is of course what you expect: when counting from 1
to N
, you count a total of N
items. More generally, when counting from x
to y
, you count y - x + 1
items (+ 1
since you include both boundaries).