pylint/checkers/base.py
def _check_in_loop(self, node, node_name):
        """check that a node is inside a for or while loop"""
        _node = node.parent
        while _node:
            if isinstance(_node, (astroid.For, astroid.While)):
                if node not in _node.orelse:
                    return

            if isinstance(_node, (astroid.ClassDef, astroid.FunctionDef)):
                break
            if (
                isinstance(_node, astroid.TryFinally)
                and node in _node.finalbody
                and isinstance(node, astroid.Continue)
            ):
                self.add_message("continue-in-finally", node=node)

            _node = _node.parent

        self.add_message("not-in-loop", node=node, args=node_name)
def _check_in_loop(self, node, node_name):
        """check that a node is inside a for or while loop"""
        _node = node.parent
        while _node:
            if isinstance(_node, (astroid.For, astroid.While)):
                if node not in _node.orelse:
                    return

            if isinstance(_node, (astroid.ClassDef, astroid.FunctionDef)):
                break
            if (
                isinstance(_node, astroid.TryFinally)
                and node in _node.finalbody
                and isinstance(node, astroid.Continue)
            ):
                self.add_message("continue-in-finally", node=node)

            _node = _node.parent

        self.add_message("not-in-loop", node=node, args=node_name)
check that a node is inside a for or while loop