I have two lists:
list1 = [0,1,2,3,4,5]
list2 = [6,7,8,9,10,11]
and I want to add List2 to List1 until we find the first sum that is larger than 10, print out the summation, and stops.
My code is:
for val1 in list1:
for val2 in list2:
if val1+val2 > 10 :
print (val1, val2, val1 + val2)
break
else:
continue
But the result is:
0 11 11
1 10 11
2 9 11
3 8 11
4 7 11
5 6 11
How to make the loop stops at the first sum? many thanks. Note: I want to maintain the for...if loop structure.