+ 5
Real use of continue operator?
Can anyone show real case code for continue operator. In the books there is only 1-2 example that doesn't cover subject
3 Antworten
+ 8
for num in range(2, 10):
if num % 2 == 0:
print("Found an even number", num)
continue
print("Found a number", num)
"""output:
Found an even number 2
Found a number 3
Found an even number 4
Found a number 5
Found an even number 6
Found a number 7
Found an even number 8
Found a number 9
see: https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
"""
https://code.sololearn.com/cp6pduDIVSAb/#py
+ 1
continue and break are used with while or for loops .
the break statement is used to stop iterations on the loop and exit when a condition is met, while the continue statement is used to skip just the next statements in the present iteration when a condition is met
https://code.sololearn.com/cUC78wkD2Zb3/?ref=app
+ 1
the continue keyword brings the script to the top of the current loop.