title: How do I detect circular logic or recursion in a multi-levels references and dependencies
body: <p>I have a graph of multi-level dependecies like this, and I need to detect any circular reference in this graph.</p>
  
  <p>A = B</p>
  
  <p>B = C</p>
  
  <p>C = [D, B]</p>
  
  <p>D = [C, A]</p>
  
  <p>Somebody have a problem like this?</p>
  
  <p>Any solution???</p>
  
  <p>Thanks and sorry by english.</p>
  
  <p>========= updated ==========</p>
  
  <p>I had another situation.</p>
  
  <p>1</p>
  
  <p>2 = 1</p>
  
  <p>3 = 2</p>
  
  <p>4 = [2, 3]</p>
  
  <p>5 = 4</p>
  
  <p>In this case, my recursive code iterate two times in "4" reference, but this references don't generate a infinite loop. My problem is to know when function iterate more than one time a reference and is not infinite loop and when is a infinite loop, to inform user.</p>
  
  <p>1 = 4</p>
  
  <p>2 = 1</p>
  
  <p>3 = 2</p>
  
  <p>4 = [2, 3]</p>
  
  <p>5 = 4</p>
  
  <p>This case is a bit diferent from 2th example. This generate a infinite loop. how can I know when cases generate a infinite loop or not?</p>