Boolean operation with script produces error which requires keyboard interrupt Cylinder 2 and Cylinder 5 are in the active screen.  Manual Boolean Difference works.  Following examples from tutorials and stackexchange, I've patched together the following script, which appears to mimic the manual operation:

import bpy
from bpy.types import Operator
from bpy.props import BoolProperty, StringProperty

#   need to spend more time on bpy: types, props,data,ops, context
xx = 15
while (xx &lt; 16):
    yy = 15
    while (yy &lt; 16):    
        #  set the 'cutter' in location
        bpy.data.objects['Cylinder.002'].location=(xx,yy,0)

        #  make sure that the base object is selected 
        bpy.data.objects['Cylinder.005'].select = False
        bpy.data.objects['Cylinder.005'].select = True

        #  set the modifier
        bpy.ops.object.modifier_add(type='BOOLEAN')
        bpy.context.object.modifiers['Boolean'].operation = 'DIFFERENCE'
        bpy.context.object.modifiers['Boolean'].object = bpy.data.objects['Cylinder.002']

        #  execute
        bpy.ops.object.modifier_apply(apply_as='DATA', modifier='Boolean')
    yy += 3
xx += 3


(not worrying about my inability to properly paste a code block for the moment)

Run Script produces the following screenshot after interrupting execution:





Aside from help with my immediate problem, would you suggest a particular tutorial on scripting?
Thanks.
From TLousky: 


  (paraphrased) The variable yy is at the wrong indent level, so it never gets incremented. Thus your inner loop runs until you interrupt it.


Use a print statement within each loop to print out your counters and find out when it's failing.

I suspect that it's failing on the first loop because although bpy.data.objects['Cylinder.005'].select = True selects the object, it neither guarantees that no other objects are also selected, nor does it set the object to active.

Use bpy.context.scene.objects.active = bpy.data.objects["Cube"] to activate the object you want to work on (FYI it might not display correctly in the viewport, even when it's working correctly). Only one object can ever be 'active' at a time, so you can also look in bpy.context.scene.objects.active to find out what (if anything) is already active.

Also use bpy.context.selected_objects check to see if any other objects are selected, to make sure none of them are interfering with your boolean. (I believe there's a method that just deselects everything, so you don't have to write your own loop to set False on every object in the scene).