'Cannot Find Symbol' error when using a 'for' loop
<p>I am a complete beginner with Java and am having trouble understanding how to pass objects around between classes and methods.  I have made some progress, however my app now fails when I try to create playing cards inside a for loop.   It works fine if I remove the loop.   Here is the first part of the class that contains the error:</p>

<pre><code>public class Testing
{
    public static void main(String[] args)
    {

   int Deal = 1;

   for(int Hand = 0; Hand &lt; Deal; ++Hand)
   {
     //instantiate and derive values for Player
     Card card1 = new Card();
     card1.setSuit();  //assign card 1's suit
     card1.setValue(); //asign card 1's value

     //instantiate and derive values for Computer
     Card card2 = new Card();
     card2.setSuit();  //assign card 2's suit
     card2.setValue(); //assign card 2's suit

     //compare the two cards and make sure they are different
     cardCompare(card1,card2);
   }

   //output the two cards to the screen
   output(card1,card2);

}
</code></pre>

<p>This is the error I get:</p>

<pre><code>Testing.java:26: error: cannot find symbol
   output(card1,card2);
          ^
  symbol:   variable card1
  location: class Testing

Testing.java:26: error: cannot find symbol
   output(card1,card2);
                ^
  symbol:   variable card2
  location: class Testing
2 errors
</code></pre>

<p>Since the code works if I remove the for loop, I'm assuming that somehow the names card1 and card2 are not visible outside the loop?  If I wanted to create ten or twenty cards, I'd want to do that in a loop, so I must be missing something about instantiating new objects and using them elsewhere in the program.  </p>

<p>Thanks for your help.</p>

<p>**Update: thanks for the initial feedback.  I see now that if I move my instantiate statements outside the for loop, I could theoretically assign new values for those objects over and over again using a loop, which is all I need to complete this particular task.   </p>

<p>I'm still curious though, is it not possible to instantiate new objects inside a loop, but still use them outside the loop?   It seems like this must be possible somehow.</p>

<pre><code>public class Testing
   {
    public static void main(String[] args)
   {

int Deal = 1;

   //instantiate and derive values for Player
     Card card1 = new Card();

      //instantiate and derive values for Computer
     Card card2 = new Card();

   for(int Hand = 0; Hand &lt; Deal; ++Hand)
   {
     card1.setSuit();  //assign card 1's suit
     card1.setValue(); //asign card 1's value

     card2.setSuit();  //assign card 2's suit
     card2.setValue(); //assign card 2's value

    //compare the two cards and make sure they are different
     cardCompare(card1,card2);
   }


   //output the two cards to the screen
   output(card1,card2);


}
</code></pre>
