+ 2
Why can't this code break? It's infinite
Using while loop and break https://code.sololearn.com/cRg9BoNL6pgM/?ref=app
7 odpowiedzi
+ 6
You defined a string x with value of x.
So when you use len(x) function it will always return 1 in answer (because string length of x is 1).
To perform such type of task, you can use another variable.
Like this :
x="x"
count = 0
while True:
print(x)
count += 1
if count>=10:
break
here count variable is intialized with value of 0.
when the loop runs again and again, it will increase value 1 by one and when it will be >= 10, loop will be break.
+ 4
Hey there,
inside your loop you're checking for the length of your x-variable to be greater/equal to 10.
Since you never change to the value of x, it always stays "x"!
Thats why you never break out of the loop.
The len()-function probably just checks the length of the x-variable, which always stays at 1 in your code ;-).
+ 4
Hi.
Try printing out the length of x, you'll see it's 1, therefore the condition in if statement will never be fulfilled and the code will never break.
I'm not really sure what are you trying to achieve? Can you please explain again?
+ 3
Hello,
x = "x"
Len(x) mean length of x which is always 1
To break the loop you should add new variable to count like so:
While i<10:
print(x)
i += 1
or for your code:
i = 0
while True:
print(x)
i += 1
if i>10:
break
+ 2
What is your point exactly? What is this code supposed to do?
0
0
If condition won't executive ... Length of x remains same