0
Exit the loop when i is 5.......find what is the error?
i=0 while i<10: if i==5: break print(i) i=i+1
5 Antworten
+ 3
#Try this
i=0
while i<10:
print(i)
i=i+1
if i==5:
break
+ 1
is that a qustion or exercise ?
+ 1
this is an infinti loop cuz the i will remain 0 u should write i+=1 inside the while block
i=0
while i<10:
if i==5:
break
i=i+1
print(i)
+ 1
i=0
while i<10:
print(i)
if i==5:
break
i=i+1
0
the point of a while loop is to give a condition to where the code can get out of the loop if said condition is met. Almost no need for a break statement. Instead of seeing if it equals 5, why not set the while loop to go if 'i' is less than or equal to 5?