title: Is there a better way to access the last element in a for loop in Java
body: <p>[edited the post to be more clear]
  The code below is supposed to represent a number of trial runs, and within each trial assume a is the number of cases that need to be checked.</p>
  
  <pre><code>while(testCaseAmt &gt; 0) {
  for(int i = 0; i &lt; a; i++) {
     if(some condition)
     //code when i is not the last element
     //then I would like to break/return here.
     if(i = a - 1)
     //code when i is the last element
     //then if the above if statement never runs during the a amt of trials
     //i will print out something else
     }
  
     testCaseAmt--;
     }
  </code></pre>
  
  <p>My question is if there is another way to access specifically the last element within a for loop to give it specific instructions. I want to loop through a set trials and if they meet the first condition, I stop the loop immediately and return. However, if the condition isn't found I still need to print out not found. </p>
  
  <p>Cheers.</p>