title: Erlang exception error: no true branch found when evaluating an if expression
body: <p>I don't understand erlang very well and for the past number of hours I've been searching up ways to fix this but I can't find any good If statement examples.</p>
  
  <p>I'm trying to use a recursive function to move discs from one hanoi tower to another. However I get the "no true branch found when evaluating an if expression". I understand as far as needing <code>true -&gt;</code> somewhere?</p>
  
  <pre><code>-module(hanoi).
  
  -export([main/1]).
  
  %% Create Towers
  main(NumDiscs) -&gt;
      TowerA = create_tower(NumDiscs),
      TowerB = [],
      TowerC = [],
      display_towers(TowerA,TowerB,TowerC),
      solve(NumDiscs,TowerA,TowerB,TowerC).
  
  %% Add the number of discs inputted to the first tower  
  create_tower(0) -&gt; [];
  
  create_tower(NumDiscs) when NumDiscs &gt; 0 -&gt;
      [NumDiscs] ++ create_tower(NumDiscs - 1).
  
  %% Display all towers
  display_towers(A,B,C) -&gt;
      io:format("-------------------------\n"),
      io:format("Tower A: ~p\n",[A]),
      io:format("Tower B: ~p\n",[B]),
      io:format("Tower C: ~p\n",[C]).
  
  
  solve(Disc,TowA,TowB,TowC) -&gt;
  if Disc &gt; 0 -&gt;
      solve(Disc - 1,TowA,TowB,TowC),
      TowBNew = [lists:last(TowA)],
      TowCNew = [lists:append(TowC,TowBNew)],
      TowANew = [lists:sublist(TowA,length(TowA) - 1)],
      display_towers(TowANew,TowB,TowCNew),
      solve(Disc - 1,TowANew,TowCNew,TowB)
  end.
  </code></pre>