afeefkhateeb afeefkhateeb -4 years ago 469
Python Question

Break outside the loop

I am new to Python. I am trying to run the following code. But every time I try to run it, the IDE says that the break is outside the loop

catname = []

print("Enter the name of the cats")

name = input()

if name == '':


catname = catname+[name]

print("The cat Names are :")

for catname in name:


Can you please help me?


Answer Source

You use break when you want to break free from a loop, to exit the loop, to jump to the nearest code after the loop.

Your code doesn't contain a loop, so nothing to break free from, hence the error.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download