For every node, you track its state: State (Unvisited) means you have not touched this node yet. State (Visiting) means you are currently processing this node or its neighbors. It is in the recursion stack. State (Visited) means you are completely done with this node and all its descendants.
The cycle rule is simple: if you move from a node to a neighbor that is State (Visiting), you have found a cycle. That neighbor is already in your current path, which forms a loop.