0

Everytime i write a code using break and continue statements i get an error that the break statement is outside loop, what wrong

22nd Feb 2018, 7:10 AM
kiumi
kiumi - avatar
8 Respuestas
+ 2
Here is how you should do it. I've explained your problem in the code. https://code.sololearn.com/ch4gRDABB8Uk/?ref=app
22nd Feb 2018, 7:36 AM
Nikolay Rusev
Nikolay Rusev - avatar
+ 8
If you want help with a particular bit of code, you can save it in the Code Playground and share it so we can check it out (three dots joined by 2 lines in the corner -> share -> copy to clipboard -> paste in Q&A with your question)
22nd Feb 2018, 7:17 AM
David Ashton
David Ashton - avatar
+ 8
If you want to print the numbers from 0 to 15, use 'while k <= 15:' If you want to print the numbers from 1 to 15, either start with k = 1 or put print(k) after k =+ 1. You don't need the if statement or the break command because a 'while' loop breaks automatically as soon as the condition is no longer True. That's why you use it 😉
22nd Feb 2018, 7:54 AM
David Ashton
David Ashton - avatar
+ 6
@kiumi That's what I was referring to. If you remove the last 2 lines you get the same result 🙂
22nd Feb 2018, 4:19 PM
David Ashton
David Ashton - avatar
0
check it out
22nd Feb 2018, 7:25 AM
kiumi
kiumi - avatar
0
David Ashton and Ammar Darwish check out the answer given by rusev, thats what i wanted. Anyway thanks to all of you.
22nd Feb 2018, 9:08 AM
kiumi
kiumi - avatar
0
yeah, i get ur point
23rd Feb 2018, 12:40 PM
kiumi
kiumi - avatar