Hacker News new | ask | show | jobs
by jjawssd 3690 days ago
That should be logical AND, not logical OR, because if you go over the limit and the right side is False, the left side will always be True if the item is not found, and True || False is still True, and the loop continues infinitely.

When you are over the iteration limit you want to trigger True && False which is False to break out of the loop where the right side False is the condition when pos > limit

Btw this is covered in Code Complete Second Edition by Microsoft Press on page 378-380

1 comments

You are right. I believed I didn't need a test for that. See what happens? :-)