13 Respostas
+ 11
Wonderwoman
i = 0
while 1==1:
print(i)
i = i + 1
if i >= 5:
print("Breaking")
break
print("Finished")
+ 4
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥
When statement is not true then loop is automatically break dear pls read code carefully
+ 4
Wonderwoman
Use meaning full condition
If condition matches loop is going on and condition is not match the use break statement to break loop
+ 2
i = 1
while i <=5:
print(i)
i = i + 1
print("Finished!")
+ 1
What if my loop depends on the input and if there's no input... How would i write that condition? I tried using an empty string but it doesn't always work
+ 1
So for no input the condition will be?
If input = '':
Break
But this doesn't always work
+ 1
Yes but this one is basic, I was looking for an explanation on no input condition
+ 1
I think this is what you mean
If there is no user input how should the code or program respond
Thats why you have "break"
But preferably what you do is use the the "while" loop in combination with "elif" and "if" or "else"
This returns a different output when your 'if' code is not inputed
+ 1
Yes
+ 1
add a break at the end if the loop
0
i = 0
while 1==1:
print(i)
i = i + 1
if i >= 5:
print("Breaking")
break
print("Finished")
In this code 2nd line, what is the purpose for writing while 1==1: What does it do?
0
Which statement ends the current iteration and continues with the next one?