title: Erlang : nested cases
body: <p>I'm very new to Erlang. I tried to find out if a list index is out of bounds (before trying it) so i wanted to do an if clause with something like</p>
  
  <pre><code>if lists:flatlength(A) &lt; DestinationIndex ....
  </code></pre>
  
  <p>I discovered that those function results cannot be used in if guards so i used case instead. This results in a nested case statement</p>
  
  <pre><code>case Destination &lt; 1 of
      true -&gt; {ok,NumberOfJumps+1};
      false -&gt;
      case lists:flatlength(A) &lt; Destination of
          true -&gt; 
              doSomething;
          false -&gt;
              case lists:member(Destination,VisitedIndices) of
                  true -&gt; doSomething;
                  false -&gt; 
                      doSomethingElse
              end
      end
  end.
  </code></pre>
  
  <p>I found this bad in terms of readability and code style. Is this how you do things like that in erlang or is there a more elegant way to do this?</p>
  
  <p>Thanks in advance</p>