Results 1 to 2 of 2

Thread: for each loop

  1. #1
    katiebear128 is offline Member
    Join Date
    Sep 2011
    Posts
    54
    Rep Power
    0

    Default for each loop

    Suppose farmArray is an array of Farm objects. Rewrite the while loop below using an extended for loop (a for-each loop):

    int k = 0;
    while(k < farmArray.length) {
    System.out.println(farmArray[k].getOwner());
    k++;
    }

    Java Code:
    for(Farm:farmArray){
    System.out.println(farmArray.getOwner[k])
    }
    what is wrong with my for each loop? I dont see it.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default Re: for each loop

    Google "for each loop" and you should find plenty of examples that show you how it should be done.

Similar Threads

  1. Replies: 1
    Last Post: 10-01-2011, 02:12 AM
  2. JTextField loop 2x for-loop WEIRD!
    By Streetproject in forum AWT / Swing
    Replies: 2
    Last Post: 02-16-2011, 05:46 PM
  3. A loop that doesn't loop
    By MichYer in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 08:44 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •