This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes am i missing something? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "am i missing something?" Watch "am i missing something?" New topic
Author

am i missing something?

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

this is some code i found for a shell sort:

it seems to me that the else portion of the
if
else if
else
statement will never be executed


SCJP
Visit my download page
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Well, what happens if increment = 2? Or 4? And what would you want to happen?
Now in this case it looks like if you start with increment = 3, it will never become 2 or 4, so maybe this is a moot point. Will increment always start at 3, or do you want to code something more general than that?


"I'm not back." - Bill Harding, Twister
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

even if it started at 4
//increment == 4
//4/2 = 2 matches if
increment = 2
//increment == 2
//2/2 = 1 matches if
increment = 1
//increment == 1
// matches else if
increment = 0
as far as i can tell, no matter what value increment starts out at, the else clause will never execute
[ April 18, 2004: Message edited by: Randall Twede ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Mmmm, looks like I misread. I was thinking of % for some reason. Looks like you're right. Perhaps the code was refactored from some other form where the else made sense, and then the else was overlooked in the refactoring. It doesn't actually affect anything, so I can imagine it being overlooked.
 
Consider Paul's rocket mass heater.
 
subject: am i missing something?
 
Similar Threads
optimize the following code
Reading byteArray at Client side
value of i?
concurrent bubble sort
u_int8_t in java