def add_loop(
        self,
        name,
        body_network=None,
        input_name=None,
        condition=None,
        condition_network=None,
        max_iterations=None,
    ):
        """
        Add a loop layer to the model that provides the functionality of a ``for``
        loop, or a ``while`` loop.
        Refer to the ``LoopLayerParams`` message in the specification (NeuralNetwork.proto) for more details.

        Parameters
        ----------
        name: str
            The name of this layer.
        body_network: NeuralNetwork
            Neural network to execute for the body of the loop.
        input_name: str
            The input blob name of this layer.
        condition: str, optional
            Condition of the loop.
        condition_network: NeuralNetwork, optional
            Neural network to execute for the condition of the loop.
        max_iterations: int, optional
            Maximum number of iterations of the loop.

        See Also
        --------
        add_loop_break, add_loop_continue, add_branch
        """

        input_names = [] if input_name is None else [input_name]
        spec_layer = self._add_generic_layer(name, input_names, [])
        loop = spec_layer.loop
        if condition_network is None:
            loop.conditionNetwork.MergeFromString(b"")
        else:
            loop.conditionNetwork = condition_network

        if condition is not None:
            loop.conditionVar = str(condition)
        if max_iterations is not None:
            loop.maxLoopIterations = (
                max_iterations if max_iterations is not None else -1
            )

        if body_network is None:
            loop.bodyNetwork.MergeFromString(b"")
        else:
            loop.bodyNetwork = body_network
        return spec_layer

        Add a loop layer to the model that provides the functionality of a ``for``
        loop, or a ``while`` loop.
        Refer to the ``LoopLayerParams`` message in the specification (NeuralNetwork.proto) for more details.

        Parameters
        ----------
        name: str
            The name of this layer.
        body_network: NeuralNetwork
            Neural network to execute for the body of the loop.
        input_name: str
            The input blob name of this layer.
        condition: str, optional
            Condition of the loop.
        condition_network: NeuralNetwork, optional
            Neural network to execute for the condition of the loop.
        max_iterations: int, optional
            Maximum number of iterations of the loop.

        See Also
        --------
        add_loop_break, add_loop_continue, add_branch
        
coremltools/models/neural_network/builder.py