code: def GetContainingWhileContext(ctxt, stop_ctxt=None):
      """Returns the first ancestor WhileContext of `ctxt`.
  
      Returns `ctxt` if `ctxt` is a WhileContext, or None if `ctxt` is not in a
      while loop.
  
      Args:
        ctxt: ControlFlowContext
        stop_ctxt: ControlFlowContext, optional. If provided, the search will end
          if it sees stop_ctxt.
  
      Returns:
        `ctxt` if `ctxt` is a WhileContext, the most nested WhileContext containing
        `ctxt`, or None if `ctxt` is not in a while loop.  If `stop_ctxt` is not
        `None`, this returns `ctxt` if it matches `stop_ctxt` in its traversal.
      """
      while ctxt:
          if ctxt.IsWhileContext() or ctxt == stop_ctxt:
              return ctxt
          ctxt = ctxt.outer_context
      return None
  
imports: import os
  import traceback
  from tensorflow.python import tf2
  from tensorflow.python.platform import tf_logging
label_desc: Use image node_id 19 for calling a global function with example usage: GetContainingWhileContext(ctxt, stop_ctxt) and returns: None, ctxt