aspose file tools*
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 Spring in Action this week in the Spring 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: 4347
    
    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: 4347
    
    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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: am i missing something?