+ 2

Continue in while loops(python)

Can someone explain what the use of continue on python is please because I don’t get it

22nd Jan 2020, 10:15 PM
Travis
3 ответов
+ 6
continue is basically used to skip code in a while loop and rerun the loop if some condition is met. For example: num = 1 while num < 10: if num % 2 == 0: #if num is even print(num) continue #we skip over the code that adds one to 10, essentially meaning this loop will continue running over and over again at 2 num += 1 In this example, if the variable num is an even number, we skip the code that adds one to num. This means the while loop will run forever.
22nd Jan 2020, 10:19 PM
Jianmin Chen
Jianmin Chen - avatar
+ 5
Use to jump directly to the next iteration in the loop.
23rd Jan 2020, 5:34 AM
Sonic
Sonic - avatar
0
In simple words, 'continue' just skip the code below and start the loops again. Use for run the loops again and skip the code below if certain cond occurred.
23rd Jan 2020, 9:09 AM
KStYLeD_
KStYLeD_ - avatar