How to return to beginning of loop in Python?

0 like 0 dislike
150 views 0 3
Is there in Python the opportunity to return to the beginning of the for loop?
Example for clarification:
for (int j = 0; j < tail; j++) { if (face == up + 1) { up++; count++; j = 0; // <- Here the desired action. } // other code.... }

Here I have the j = 0 instruction, allows you to perform repeated pass through the loop.
If there in Python any method for setting pointer
zero offset, something like analog reset() from PHP?
There any options or while use? But this is not elegant...
asked by | 150 views

3 Answers

0 like 0 dislike
0
But such an option is right for You?

return to beginning of loop
it is in fact - abort current cycle and start it again, so...

the cycle of "stuff" in function, and subject to the conditions to trigger it again (a La recursion), followed by a break. Just look at the situation, to not go into infinite recursion.
Not come up with explanatory example for such a task (Yes You have it and so there, just a question) - because I will illustrate with input():
def foo(): for i in range(5): n = input() if n == '42': foo() break else: print(n*10) foo() print('end') ##40 ##40404040404040404040 ##41 ##41414141414141414141 ##42 ##1 ##1111111111 ##2 ##2222222222 ##3 ##3333333333 ##4 ##4444444444 ##5 ##5555555555 ##end
answered by
0 like 0 dislike
0
n = 0 while(True): for i in range(10, 20): if n == 1: n += 1 break if i == 15: n += 1 print(i) else: break


here an example is shown how to start from a running cycle this cycle once again
answered by
0 like 0 dislike
0
while quite elegant.
answered by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
0 like 0 dislike
0 answers
24,522 questions
45,948 answers
0 comments
454 users