can I use more #continue command in while loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

can I use more #continue command in while loop

I just create a code using while loop the question is print 1 to 5 and 10 to 15 using while loop and continue and break command this is my right code: i=0 while True: i=i+1 if i<=5: print(i) continue if i==5: i=i+5 if i>=10: print(i) if i==15: break print('finish') and this is my wrong code: i=0 while True: i=i+1 if i<=5: print(i) continue if i==5: i=i+5 continue if i>=10: print(i) continue if i==15: break print('finish')

15th Nov 2020, 10:13 AM
Antony Praveenkumar M
Antony Praveenkumar M - avatar
1 Answer
+ 3
The Q&A is a place to ask for help with problems with your codes. It's not a place for showing how you fixed them. You want to make your code DRY (Don't Repeat Yourself). How about this? i = 0 while True: i += 1 if 5 < i < 10: continue if i > 15: break print(i) print("finish") It saves 6 i's, 2 if's and a print. 🙂
15th Nov 2020, 10:43 AM
David Ashton
David Ashton - avatar