In Python, can the break and continue statements only be used with if? The picture below is from Liao Xuefeng’s website
No, continue and break must be used in for, while and other loops. Break and continue cannot be used in a separate if statement. Give me an example
# Example 1 for a in [1, 2, 3, 4]: if (a == 1): continue else: print(a) # 2 # 3 # 4
# Example 2 for a in [1, 2, 3, 4]: print(a) continue
Continue and break cannot be used for separate if
# Example 3 if True: continue # SyntaxError: 'continue' not properly in loop
Of course not, break and continue are used to break out of the loop
No, continue and break must be used in for, while and other loops. Break and continue cannot be used in a separate if statement.
Give me an example
Continue and break cannot be used for separate if
Of course not, break and continue are used to break out of the loop