View Single Post
  #3  
Old 05-01-2008, 06:34 PM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
Why would I put a break in? It iterates to find the smallest distance, Zero.

Having worked with professional development teams I can honestly say this is the cleanest bit of code I've written in months x.x I am not proud of this fact.

Some psuedocode:
PHP Code:
public int findSmallestIndex(int[] values){
  
initialize variable to hold index of smallest value ( -1 might be a good number here)
  
initialize variable to hold value of smallest value (Integer.MAX-VALUE might be a good number here)
  for 
length of values
    
if i value smallest value
      smallest value 
i value
      smallest index 
i   
 
  
return i

Reply With Quote