Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-30-2007, 12:48 PM
Member
 
Join Date: Jul 2007
Posts: 1
Username is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-30-2007, 06:04 PM
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-30-2007, 06:37 PM
Member
 
Join Date: Jul 2007
Posts: 72
Swamipsn is on a distinguished road
Try with recursion
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +3. The time now is 07:41 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org