Well, I thought this would really be easy, but I guess even in Chapter 1 I already assume too much ^^ Most criticism about the book was jumping to conclusions too quickly without explaining all the steps in greater detail, but I guess then not all the games would even fit into the book.
Ok, here we go:
The 2 for loops go through every single tile that is visible on the screen. Thanks to our resolution (1024x768) we can fit the CityGroundSmall.dds textures 4 times horizontally because it is 256x256 pixel in size (1024/256 = 4). Vertically it would fit 3 times (768/256 = 3), but since we allow scrolling up and down, we also render one above it and one below it to allow scrolling in both directions.
In case the resolution is different (I guess the standard is now 800x600) I also added one extra tile in both direction with the <= command, which will add another tile in case the resolution is not a multiple of 256.
This means we go through a grid of 5x6 tiles, x goes from 0 to 4, y goes from -1 to +4. The scrollPosition is helper value to scroll up and down, which gets modulated (the % command) by the height to make sure we never run out of the visible area.
To understand the code better, try to just render 2x2 tiles (use for (int x=0; x<2; x++) etc.) and see what happens when you scroll around, then increase the number of tiles until it looks correctly. That is exactly what I did when I wrote this code :)
http://abi.exdream.com