File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

am i missing something?

 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic