Help with for and while loop


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Help with for and while loop

  1. #1
    Join Date
    Oct 2003
    Posts
    21

    Unhappy Help with for and while loop

    I want to rewrite the body of a code so that the For loop is replaced with an equivalent while can someone please help with a while loop ASAP!!
    Code:
    /**
         * Print the hourly counts.
         * These should have been set with a prior
         * call to analyzeHourlyData.
         */
        
    public void printHourlyCounts()
        {
            
            System.out.println("Hr: Count");
            for(int hour = 0; hour < hourCounts.length; hour++) {
                System.out.println(hour + ": " + hourCounts[hour]);
            }
           
        }
    
    and also how do i rewrite this code with a FOR LOOP?!?
    public void listNotes()
        {
            int index = 0;
            while(index < notes.size()) {
                  System.out.println(notes.get(index));
                   index++;
               }
         }
    [ArchAngel added CODE tags]

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    What problem are you having?
    ArchAngel.
    O:-)

  3. #3
    Join Date
    Nov 2003
    Posts
    7
    while loops and for loops are pretty much the same. I have no clue what your first example is, but here is what you could do with your second one:

    for(int index =0; index<notes.size();index++)
    System.out.println(notes.get(index));

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center