for i in range(1, 4): for j in range(1, 4): print('i =', i, 'j =', j) if i == 3 and j == 1: print('continues inner loop when i =', i, 'j =', j) continue - just does nothing and does not miss - Vasily Pelikan
- should move to a new i, but he continues to j - Vasily Pelikan
- oneWhat do you want to miss? - Grulex
- I want, when i = 3 and j = 1, the cycle should skip i = 3, j = 2; i = 3, j = 3; and passed to i = 4 - Vasily Pelikan
|
2 answers
In this case, instead of continue you need to use break , you don’t want to go to the next iteration of the nested loop, but you want to exit it altogether
- I want this problem. - Vasily Pelikan
- You want to go to the next iteration of iteration
i. From bustingjyou need to quit completely - Grulex - Got it. Thank you - Vasily Pelican
|
for i in range(1, 5): for j in range(1, 5): if i == 3 and j <= 4: print('continues inner loop when i =', i, 'j =', j) continue print('i =', i, 'j =', j) or
for i in range(1, 5): for j in range(1, 5): if i == 3 and j == 1: break print('i =', i, 'j =', j) Conclusion
i = 1 j = 1 i = 1 j = 2 i = 1 j = 3 i = 1 j = 4 i = 2 j = 1 i = 2 j = 2 i = 2 j = 3 i = 2 j = 4 continues inner loop when i = 3 j = 1 continues inner loop when i = 3 j = 2 continues inner loop when i = 3 j = 3 continues inner loop when i = 3 j = 4 i = 4 j = 1 i = 4 j = 2 i = 4 j = 3 i = 4 j = 4 |