def call_for_nodes(node, callback, recursive=False):
 result = callback(node)
 if (recursive and (not result)):
  for child in get_child_nodes(node):
   call_for_nodes(child, callback, recursive)

def call_for_nodes ( node , callback , recursive = False ) : result = callback ( node ) if ( recursive and ( not result ) ) : for child in get_child_nodes ( node ) : call_for_nodes ( child , callback , recursive )
if callback returns true the child nodes are skipped .