curriculum/challenges/english/blocks/workshop-binary-search/683ec95f2f8781355556ff81.md
You need to test out things so you will understand the flow of the algorithm at this initial stage.
To do that, you need to first break out of the loop. That's because the current implementation will only allow one iteration, so if the condition is not met, there will be an infinite loop.
Just after the ifstatement, use the break keyword to break out of the while loop. Then, after the while loop, return an empty list to signify that the value was not found.
You should use the break keyword to break out of the while loop after the if statement.
({
test: () => assert(runPython(
`_Node(_code).find_function("binary_search").find_whiles()[0].find_body().has_stmt("break")`)
)
})
You should return an empty list after your while loop.
({
test: () =>
assert(
runPython(
`_Node(_code).find_function("binary_search").has_return("[]")`
)
)
})
def binary_search(search_list, value):
path_to_target = []
low = 0
high = len(search_list) - 1
while low <= high:
mid = (low + high) // 2
value_at_middle = search_list[mid]
path_to_target.append(value_at_middle)
--fcc-editable-region--
if value == value_at_middle:
return path_to_target
--fcc-editable-region--