title: Process border cells of matrix
body: <p>I would like to process every border cell of a <em>nxn</em> matrix. For example, for <em>int array[5][5];</em> algorithm should process every <em>x</em> element, so it has the form</p>
  
  <pre><code>   x x x x x 
     x - - - x
     x - - - x
     x - - - x
     x x x x x
  </code></pre>
  
  <p>What's the best way to process this cells? What about if it is a 3-dimensional array? Thanks in advance, and sorry for the matrix representation.</p>
  
  <p><strong>Edit I</strong> I would like to use only one loop in order to avoid nesting loops or recursion.</p>