Results 1 to 3 of 3
  1. #1
    Username is offline Member
    Join Date
    Jul 2007
    Posts
    1
    Rep Power
    0

    Smile looping a function

    Hi!

    I want to loop one of like, 5 functions a 100 times. I don't wanna put the loop in each of those 5 functions.

    The loop code itself is the same each time, only a different function is used. I don't wanna use a if statement in the loop or a select case as that is inefficient.

    I'm thinking something like having a looping class and placing the loop there, calling to an execute function - which is overridden by derived classes with those functions in them.

    Any ideas?

    Thanks
    Last edited by Username; 07-30-2007 at 12:48 PM. Reason: typo

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    My thoughts are the same. Create an interface that defines a method that the loop method will call 100 times. Then create a class for each method you want to loop that implements the interface. Then just call the loop method and pass in a different class each time.

  3. #3
    Swamipsn is offline Member
    Join Date
    Jul 2007
    Posts
    74
    Rep Power
    0

Similar Threads

  1. How to use a function in java
    By olikhvar in forum New To Java
    Replies: 2
    Last Post: 02-16-2008, 03:57 AM
  2. Need a little help with a function!
    By Nuluvius in forum New To Java
    Replies: 3
    Last Post: 02-08-2008, 12:33 AM
  3. I want to add function
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:25 AM
  4. Java Looping and decision
    By susan in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:29 AM
  5. function name
    By osval in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 09:56 PM

Posting Permissions

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