Python: break outside loop

Asked 2 years ago, Updated 2 years ago, 19 views

print('*'*20)
menu = int(input("""1. Add name
2. Delete Name
3. Modify Name
4. Termination
Select menu: "")

mylist = []

new_name = input('name :')

mylist.append(new_name)

print(mylist)

i=1
if menu == 1:
    if i == 1:
        print(mylist.append(new_name))
        i+=1

    else:
        if new_name in mylist:
            print(mylist)
        else:
            print ('Not Affected')

elif menu == 2:
    if new_name in mylist:
        print(mylist)
    else:
        print ('Not Affected')

elif menu == 3:
    if new_name in mylist:
        a = input ('new name:')
        print(mylist.reverse(a))
    else:
        print ('Not Affected')

else:
    break

In this process, an error called break outside loop appears. What should I do?

python

2022-09-20 16:34

1 Answers

break is used when you want to stop repeating in repetitive statements such as for and while and run the next code.

There is no repeat statement in the code you wrote, but an error occurs because you use break.

Put the whole code inside the while statement and try to correct it again


2022-09-20 16:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.