“Python Break” Kod odpowiedzi

Python podczas kontynuowania

## 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

Przykład oświadczenia o przerwie w Pythonie

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

Break Python

# Use of break statement inside the loop

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

print("The end")
SAMER SAEID

Odpowiedzi podobne do “Python Break”

Pytania podobne do “Python Break”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu