Break & continue | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Break & continue

I need to understand more the below example : also if you can recommend me a youtoub channel for Python data since i = 0 while True: print(i) i = i + 1 if i >= 5: print("Breaking") break print("Finished")

5th Jun 2022, 11:56 AM
Mohamed Adli
3 Answers
+ 2
The code above do the next: set var i to 0(at the beginning) start a infinite loop(until break) print the most resent value of i add 1 to i check if i is bigger or equal than 5 if true, it breaks if false it continues I hope this could help you.
5th Jun 2022, 12:27 PM
Erick Fernando Carvalho Sanchez
Erick Fernando Carvalho Sanchez - avatar
+ 1
Mohamed Adli i = 0 while True: # will loop forever print(i) # prints the iteration i = i + 1 # increments iteration if i >= 5: # conditional statement print("Breaking") # output break # breaks the loop print("Finished") # This statement is outside the loop so will happen regardless.
5th Jun 2022, 12:28 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
أشرحها لك بالعربي يمكن توضح أكثر: السطر الأول افتراضياً تم تعيين قيمة i صفر في السطر الثاني الشرط هو صحة الشرط دائماً السطر الثالث المخرج قيمة i السطر الرابع إضافة واحد لقيمة i السطر الخامس إذا أصبحت قيمة i خمسة او أكبر المخرج كلمة breaking في السطر السادس وإيقاف الشرط في السطر السابع وفي السطر الأخير المخرج كلمة finished the output i=0 i=0+1=1 i=1+1=2 i=2+1=3 i=3+1=4 i=4+1=5 # this will not be printed because : the conditional statement will be break if i=5 Breaking Finished
5th Jun 2022, 8:30 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar