[lang-ref] ( break_out_of_nested_loop ) ( python )
def test_break_out_of_nested_loop():
pytest.skip('Not supported')
def test_break_out_of_nested_loop_alternative():
# make it function
def search_value_with_break(v):
for i in range(10):
for j in range(10):
if i * 10 + j == v:
break # breaks only internal loop
# outer loop continues, so i,j end up as the last values (9,9)
return (i, j)
def search_value_with_return(v):
for i in range(10):
for j in range(10):
if i * 10 + j == v:
return (i, j)
raise Error('unexpected')
i, j = search_value_with_break(25)
assert (i, j) == (9, 9) # `break` exits only the inner loop, so the outer loop continues.
i, j = search_value_with_return(25)
assert (i, j) == (2, 5)