84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
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