what is the use of continue | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is the use of continue

23rd Jan 2017, 10:15 AM
pushkar
2 Answers
+ 1
It lets you jump an iteration in a loop. Let's say you have a for loop from 0 to 10. And you write in the code an if condition for i==5, and you write continue right after that. This means that when the loop reaches that 5, and as soon as it sees the condition, it will skip the remaining part of code in the loop. The easiest example to test this is if you write a for loop, and then make a check if i % 2 == 0, and if that is true, write continue. And below the if statement (outside its scope), let the program print the current i. This will show you only the odd numbers.
23rd Jan 2017, 10:50 AM
Petar Dimitrov
Petar Dimitrov - avatar
0
thanks man
23rd Jan 2017, 11:01 AM
pushkar