“Cómo terminar un bucle de bucle Python” Código de respuesta

Infinito mientras Python

#infinite While on Python

while True:
  print('Hello World!')
Panicky Pelican

Mientras bucle en Python para ¿Quieres continuar?

while input("Do You Want To Continue? [y/n]") == "y":
    # do something
    print("doing something")
Clear Camel

Mientras bucle en Python para ¿Quieres continuar?

while True:
    # some code here
    if input('Do You Want To Continue? ') != 'y':
        break
Clear Camel

Cómo terminar un bucle de bucle Python

while True:
    x = input('Enter something \n')
    if x == "TTYL":
        print("Talk to you later")
        break <--- Key word
Donald Duck

Mientras que el bucle python

# While loop counting to 10 in 2's

i = 2

while i <= 10:  # While i is less than or equal 10, it will add 2
  print(i)
  i = i + 2
Helpless Hamster

python cómo terminar mientras bucle

# a 'while' loop runs until the condition is broken
a = "apple"
while a == "apple":
  a = "banana" # breaks loop as 'a' no longer equals 'apple'
  
# a 'for' loop runs for the given number of iterations...
for i in range(10):
  print(i) # will print 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

# ... or through a sequence
array = [3, 6, 8, 2, 1]
for number in array:
  print(number) # will print 3, 6, 8, 2, 1
panda

Respuestas similares a “Cómo terminar un bucle de bucle Python”

Preguntas similares a “Cómo terminar un bucle de bucle Python”

Más respuestas relacionadas con “Cómo terminar un bucle de bucle Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código