Break
break
is a special command to leave the loop at any moment. It can be used either inside general finite loops or infinite loops with constantly True conditions, like while True:
.
123456789a = 96 while True: if a < 101: a += 1 elif a > 101: a -= 1 else: print('a reached 101') break
This loop could be infinite, but we're lucky to have the break
after a
becomes equal to 101. After that, loop is over and next lines of code are executing.
Swipe to start coding
Simulate the game. For the current number of user's points
increment it by 5 if it is even number, or decrease by 3 if it is odd number. The game is over when value of points
reaches 17. If it happened, print the message The game is over
and leave the loop.
Solution
Merci pour vos commentaires !
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Awesome!
Completion rate improved to 6.25
Break
Glissez pour afficher le menu
break
is a special command to leave the loop at any moment. It can be used either inside general finite loops or infinite loops with constantly True conditions, like while True:
.
123456789a = 96 while True: if a < 101: a += 1 elif a > 101: a -= 1 else: print('a reached 101') break
This loop could be infinite, but we're lucky to have the break
after a
becomes equal to 101. After that, loop is over and next lines of code are executing.
Swipe to start coding
Simulate the game. For the current number of user's points
increment it by 5 if it is even number, or decrease by 3 if it is odd number. The game is over when value of points
reaches 17. If it happened, print the message The game is over
and leave the loop.
Solution
Merci pour vos commentaires !
Awesome!
Completion rate improved to 6.25single