+ 2
{ANSWERED}What does the while true go on
i = 0 while True: print(i) i = i + 1 if i >= 5: print("Breaking") break print("Finished")
13 ответов
+ 4
On each iteration, i is increased by one and the loop would go on infinitely (while True) if there wasn't the if-statement. If i gets larger or equal 5, the break-statement stops the loop.
+ 3
Lz1234
While true sets a condition that will continue to iterate until you break the loop as you have done in your example.
You could set a condition that will ultimately become false, which would break the loop without the 'break' statement.
IE:
i = 0
while i < 6:
print(i)
i = i + 1
print("Finished")
+ 2
Does every boolean code need to start with
While true or just by for loops or while loops
+ 2
Lisa
Rik Wittkopp
Thanks
+ 1
Go to Code section, click +, select the programming language, insert your code, save. Then come back to this thread, click +, Insert Code, sort for My Code Bits, select your code.
Check the indentation. I assume that an erroneous indentation could be the issue
+ 1
https://code.sololearn.com/c5EdvbFb1CTS/?ref=app
Is this good
+ 1
Look okay to me. Is it the output you were expecting?
+ 1
It works just trying to understand the code trying to undrestand what word it goes on
+ 1
Thanks
+ 1
The condition in the head of the while loop could also be a comparison:
while i >= 5:
i += 1
print(i)
0
I think the indentation got messed up. Please put your code in a script on sololearn playground rather than copying it in the description.
0
That depends on the context... it should be something that can be evaluated to a boolean