title: How to implement a condition with two loops
body: <pre><code>public void PlayforMe()
  {
      for (int i=game.size()-1;i&gt;=1;i--)
      {
          Card a = game.get(i);
          Card b = game.get(i-1);
          if (a.getSuit().equals(b.getSuit()) | (a.getCardNum().equals(b.getCardNum())))
          {
              game.remove(b);
              break;
          }
      }
  
      for (int j=game.size()-1;j&gt;=3;j--)
      {
          Card c = game.get(j);
          Card d = game.get(j-3);
          if (c.getSuit().equals(d.getSuit()) | (c.getCardNum().equals(d.getCardNum())))
          {
              game.set(j-3,game.get(j));
              game.remove(j);
              break;
          }
      }
  }
  </code></pre>
  
  <p>I have written this piece of Java code for a solitaire type game I'm making in Java code. I'm very new to the language (and programming in general). I have an arrayList for my deck and an arrayList for my 'game'. In this method/move I have it so it will find the card nearest the end of the dealt cards and 'swap' it with the card directly before it if the suit or the card number are the same. </p>
  
  <p>If this move isn't an option with the cards dealt then I need it to go through the second loop which finds the card nearest the end of the dealt cards and 'swaps' it with the card [3] places before it if the suit or the card number are the same.</p>
  
  <p>They work individually, but I can't get a condition working (e.g. I've tried the if statement) that will go through the first loop, and if it doesn't successfully remove a card it will go through the second loop.</p>
  
  <p>The method should only preform one move, prioritising moving a card onto the card next(before) it if the conditions are met. I can make it so it'll go through both loops (i.e. putting the piece of code into two methods and calling them both from my menu) but I need it to do the first loop and only do the second if the first one turns out unsuccessful (i.e. card b isn't removed/game.remove(b); isn't called.)</p>
  
  <p>If anyone has any suggestions I'd appreciate it :)</p>