We have answer of your question!

100% solved queries, no empty question

0

Currently having trouble with breaking this for loop. I want to break it if the variable is not found in this list so it can move two another for loop. It expects an indented block for the top of the for loop, but if I change the position of the break or of the start of the for loop, it doesnt work. help!

while cyclenumb <= 10000:

    for x in userpassword[k]:
        for z in lowercaselist:
            if x in z:
                newpasswordlist.append(z)
                k +=1
                break
        else:

    for x in userpassword[k]:
        for z in uppercaselist:
            if x in z:
                newpasswordlist.append(z)
                k +=1
                break
        else:
Question author Mansa | Source

Answer


1


You'll need to break out of each loop separately, as people have mentioned in the comments for your question, break only stops the loop which it's in

for x in userpassword[k]:
    for z in lowercaselist:
        if x in z:
            newpasswordlist.append(z)
            k +=1
            break

     if x in z: # added an extra condition to exit the main loop
        break

You'll need to do this for both loops

If you want to break out of the while loop as well, then you can add if x in z: break in that loop aswel

Answer author Tom-fuller

Tickanswer.com is providing the only single recommended solution of the question Break for loop in an if statement under the categories i.e python , list , if-statement , for-loop , break , . Our team of experts filter the best solution for you.

Related Search Queries:

how to come out of if loop in java , break inside if statement inside loop ,


You may also add your answer

Thanks for contributing an answer to Tick Answer!