Read up on the turtle API, as it gives you the commands you can use most easily. Also, read up on this: http://www.lua.org/manual/5.2/ , specifically control structures, for statement, and logical operators. These are the pieces that will tie all your turtle api commands together.