Can someone tell me the error in my program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone tell me the error in my program

number = ["fifty","hundred","thousand"] for x in number: print(x) if x == "hundred": break I'm getting a break outside loop error

2nd Jan 2024, 4:24 PM
Nandita Gan Chaudhuri
Nandita Gan Chaudhuri - avatar
3 Answers
+ 13
Check the INDENTATION of the if-statement
2nd Jan 2024, 4:50 PM
Lisa
Lisa - avatar
+ 6
The issue in your code is related to indentation. The break statement should be indented to be part of the loop block. Here's the corrected code: number = ["fifty", "hundred", "thousand"] for x in number: print(x) if x == "hundred": break
2nd Jan 2024, 5:53 PM
卂ㄚㄩ丂卄
卂ㄚㄩ丂卄 - avatar
+ 3
Nandita Gan Chaudhuri , It will probably be easier for you to catch your own indentation errors in the future if you make the indentations deeper so they are easier to see. The Python convention is four spaces per indentation level. It will make it easier for others to read your code too, especially in the comments section, where spaces are narrower than in the editor.
3rd Jan 2024, 12:38 AM
Rain
Rain - avatar