The Depth-First Search algorithm is designed to browse all the nodes of a graph only once. The algorithm starts browsing at a given node, then browses recursively the other reachable nodes by following the outgoing edges of the nodes.
By remembering all the browsed nodes and its parent (that is, the node those one of its outgoing edges permitted to reach the node), we can detect cycles if we notice that a node previously processed can be found by searching the ancestors of the node.
If one parent in the ancestors hierarchy is the node itself, it is a cycle that is candidate to be considered as a COBOL loop. If not, we have reached a node previously processed that is not part of a cycle in the diagram: it will be interpreted as a GOTO statement between two COBOL pieces of code.