Learning Perl is imho the best book for beginning to code. It is clear, as short as it can be, fun, explains why not just how, encourages efficiency, has exercises, etc. To this day I still recommend it even if opportunities to use Perl are gone.
But yet, Randal had beat into me the idea of explaining "why" on everything. You'll notice the basic pattern in Learning Perl and my other writing is that we show the expedient thing, tell you how that fails, improve that a little, show how that fails, and end up at a better final solution. That path shows quite a bit that's ancillary to the task at hand, but also shows how the pieces work together and how different parts affect the solution. I'm usually frustrated by other language tutorials where they say "just do this" without saying anything about why the various parts are there.
Learning Perl was originally written with a C programmer audience, so it assumes that the reader is comfortable with ideas such as variables and looping. I have another book I might recommend for beginning to code: Squeak: Learn Programming with Robots. Sure, it's Smalltalk and literally written for teenagers, but I think it works. It reminds me of the fun days of Logo.