“Python Break” Código de respuesta

Python mientras continúa

## When the program execution reaches a continue statement, 
## the program execution immediately jumps back to the start 
## of the loop.
while True:
    print('Who are you?')
    name = input()
    if name != 'Joe':
        continue
    print('Hello, Joe. What is the password? (It is a fish.)')
    password = input()
    if password == 'swordfish':
        break
print('Access granted.')
SkelliBoi

Ejemplo de declaración de descanso en Python

while True:
    num = input("Enter the number: ")
    if num == "":
        break
    number = int(num)
    print("The square of the number ",number,"  is: ", number*number)
print("User entered a null string")
Outrageous Ostrich

Python Break

for i in range(5): # For loop
  if i == 3:
    break # Exits out of the for loop, even when not finished
  else:
    print(i)
    
number = 1
while number <= 5:
  if number == 4:
    break # Exits while loop
  else:
    print(number)
Ninja Penguin

Romper Python

# Use of break statement inside the loop

for val in "string":
    if val == "i":
        break
    print(val)

print("The end")
SAMER SAEID

Respuestas similares a “Python Break”

Preguntas similares a “Python Break”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código