The for statement has two important keywords: break and else. The keyword break quits the for loop even if the list we are iterating is not exhausted:
x_values=[0.5, 0.7, 1.2]
threshold = 0.75
for x in x_values: if x > threshold: break print(x)
The finalizing else checks whether the for loop was broken with the break keyword. If it was not broken, the block following the else keyword is executed:
x_values=[0.5, 0.7]
threshold = 0.75
for x in x_values: if x > threshold: break else: print("all the x are below the threshold")