Real use of continue operator? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

14th Jul 2018, 11:43 AM
tardigrade
tardigrade - avatar
3 Answers
+ 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
14th Jul 2018, 12:14 PM
David Ashton
David Ashton - avatar
+ 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
18th Jul 2018, 11:37 AM
Ramzi Zelfani
Ramzi Zelfani - avatar
+ 1
the continue keyword brings the script to the top of the current loop.
22nd Jul 2018, 11:03 AM
sammy b
sammy b - avatar