Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Junky

Thread: Repeating too many times.

  1. #1
    trishtren is offline Member
    Join Date
    Feb 2011
    Posts
    53
    Rep Power
    0

    Default Repeating too many times.

    hello again, im having a problem with a loop. It repeats 3 times for some reason when it should only perform once and i cannot figure out why.
    Java Code:
      
    Java Code:
    public Stack<item> place(Stack<item> item) {
            Stack<item> itempile = new Stack<item>();
            for (int i=0;i<10;i++)
            {
            
                itempile.push(item1.pop()); 
    
            }
          
         
    
    return itempile;
    
    }
    The problem is that it performs correctly only on option 3 for some reason. If i choose option 1 it performs place 3 times, if i perform option 2 it repeats twice and if i perform option 3 it works the way i expect it to everytime. Any clues on where this looping issue is going wrong would be nice :)
    Last edited by trishtren; 11-11-2011 at 01:11 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Repeating too many times.

    You need breaks within your switch block. Please re-read the tutorial on use of a switch construct, and it will show you exactly how to do this.

  3. #3
    trishtren is offline Member
    Join Date
    Feb 2011
    Posts
    53
    Rep Power
    0

    Default Re: Repeating too many times.

    Oooh thanks so much, after inserting breaks it works the way i expect. Im still re-reading the switch tutorial though :p Thanks!

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

    Default Re: Repeating too many times.

    What switch?

    Please do not delete information from your posts as it makes it very confusing to others who read it at a later time.
    Fubarable likes this.

  5. #5
    trishtren is offline Member
    Join Date
    Feb 2011
    Posts
    53
    Rep Power
    0

    Default Re: Repeating too many times.

    ah sorry, i will refrain from it in future.

Similar Threads

  1. Repeating words
    By Junky in forum Suggestions & Feedback
    Replies: 5
    Last Post: 08-18-2011, 06:42 AM
  2. Replies: 1
    Last Post: 02-11-2011, 06:57 AM
  3. jxl repeating rows
    By mermaid in forum New To Java
    Replies: 0
    Last Post: 01-14-2011, 04:59 PM
  4. Repeating
    By AbdulAziz Bader in forum New To Java
    Replies: 3
    Last Post: 05-06-2010, 12:35 AM
  5. Repeating Do-While Statement
    By adamg106 in forum New To Java
    Replies: 10
    Last Post: 04-22-2010, 08:09 AM

Posting Permissions

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