Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

What is a "Top Testing Loop" in Java?

Options
  • 18-01-2007 2:56am
    #1
    Closed Accounts Posts: 19,080 ✭✭✭✭


    What is a "Top Testing Loop" in Java?

    Thanks.


Comments

  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    a top testing loop is where you do your testing at the top (while loops)
    eg.
    x=0
    while (x!=0)
    {
       .....
       .....
    }
    

    bottom testing whould be where you do your testing at the bottom (do while loops)
    eg.
    x=0
    do
    {
      ....
      ....
      ....
    }
    while (x!=0)
    

    i don't think it's specific to java, it's more of a conventional naming method for loops.


  • Closed Accounts Posts: 19,080 ✭✭✭✭Random


    That's it Cremo? Why couldn't google tell me that?

    Just going through some sample exam papers for Java and saw that question. It had me stumped.

    Thanks.


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    i'm pretty sure that's all there is to it, google didn't crop up with much for me either.

    i remember it been mentioned in a C lecture i had once, so i'm assuming it's sticks for java aswell as C.


  • Closed Accounts Posts: 19,080 ✭✭✭✭Random


    Cremo wrote:
    i'm pretty sure that's all there is to it, google didn't crop up with much for me either.

    i remember it been mentioned in a C lecture i had once, so i'm assuming it's sticks for java aswell as C.
    Yeah .. generally things do.

    Of course, if anyone else thinks there's more to it please let me know!

    Thanks Cremo.


  • Registered Users Posts: 6,180 ✭✭✭Talisman


    A top testing loop is where you test the condition before executing the loop.
    e.g. while (condition) { loop }.
    int x = 1;
    while (x==0) {
    	System.out.println(x);
    	x--;
    };
    System.out.println(".");
    
    Output:
    .

    A bottom testing loop executes the loop before testing the condition.
    e.g. do { loop } while (condition).
    int x = 1;
    do {
    	System.out.println(x);
    	x--;
    } while (x==0);
    System.out.println(".");
    
    Output:
    1
    0
    .

    A bottom testing loop will execute the code within the loop at least once even if the condition is false.


  • Advertisement
Advertisement