When i am using break statement in if loop , an error occurs stating that break statement is outside the loop!! Please help! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

When i am using break statement in if loop , an error occurs stating that break statement is outside the loop!! Please help!

31st Dec 2017, 1:04 PM
Johnbritto Johnson
Johnbritto Johnson - avatar
6 Answers
+ 1
An if statement is no loop, so if you just wrote "break" inside an if statement, it is not inside a loop. Use while or for loops instead.
31st Dec 2017, 4:24 PM
Moritz Vogel
Moritz Vogel - avatar
+ 8
As others indicated -- without seeing it will be hard to determine what the problem is, exactly. Perhaps it's a problem of proper indentation? If you have an indented block of code, the break command should usually be indented at least a level deeper.
31st Dec 2017, 1:36 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
Can I see your code?
31st Dec 2017, 1:09 PM
Dapper Mink
Dapper Mink - avatar
+ 2
Not without seeing the code.
31st Dec 2017, 1:30 PM
josh mizzi
josh mizzi - avatar
+ 1
thanks for your reply guys! I got it right! what Moritz said was the problem in my code! I used if statement and it was not inside of for or while loop!..
31st Dec 2017, 4:46 PM
Johnbritto Johnson
Johnbritto Johnson - avatar
0
Moritz raises a good point.
31st Dec 2017, 4:26 PM
josh mizzi
josh mizzi - avatar