D
D
Danil Samodurov2020-05-28 22:11:51
Python
Danil Samodurov, 2020-05-28 22:11:51

Why doesn't the function continue the loop?

Why doesn't this code work?

list = [1, 2, 3, 4, 5, 6, 7, 8]

for i in list:    
    def not_eight():
        if i != 8:
           return continue
        else:
            return break


I'll explain in more detail. I am working with tkinter library. I create a button
btn = Button(window, text="Продолжить", command=next)

The command command sends to the next() function. I need this function to continue the for loop it's inside with a new value.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
ishmatov_rus, 2020-05-29
@samodurOFF

return should return value
def not_eight(i):
if i == 8:
return True
list = [1, 2, 3, 4, 5, 6, 7, 8]
for i in list:
if not_eight(i):
break

A
Andrey_Dolg, 2020-05-28
@Andrey_Dolg

Well, you defined the function 8 times, the code honestly did everything. Except for a small nuance (XD) in this approach, the code is working. What do you want the code to do?

1
1 1, 2020-05-29
@Gear_up

def not_eight():
    if i != 8:
        return continue
    else:
        return break

list = [1, 2, 3, 4, 5, 6, 7, 8]

for i in list:    
    not_eight()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question