title: Checking if a number is triangular
body: <p>So i have this predicate triangular(N) in which N is a number and this predicate return true if a number is a triangular number.</p>
  
  <p>My problem is this for some reason my predicate does an infinite loop instead of just summing the numbers until the N.</p>
  
  <p>Example:</p>
  
  <p>?- triangular(3).
  3
  true</p>
  
  <p>and it doesnt end.</p>
  
  <p>So basically this is priting the sum of numbers until 3 but its doing something i dont understand.</p>
  
  <p>Program:</p>
  
  <pre><code>triangular(N) :- triangular(N,0).
  
  triangular(N,AC) :- triangular(N,AC,N).
  
  triangular(N,AC,0) :-  write(AC).
  
  triangular(N,AC,CONT) :- NCONT is CONT - 1,
                           NAC is AC + NCONT,
                           triangular(N,NAC,NCONT).
  </code></pre>