📅  最后修改于: 2023-12-03 15:35:41.308000             🧑  作者: Mango
In Python, the while
loop is used to execute a block of code repeatedly until a certain condition is met. The loop will continue to execute as long as the specified condition is true.
One common use of the while
loop is to collect user input until the user enters a specific value, such as "exit".
Here is an example of using while
loop in Python:
my_input = ''
while my_input != "exit":
my_input = input("Enter a value (type 'exit' to quit): ")
print("You entered:", my_input)
print("Loop exited")
In this example, the loop will continue to execute until the user enters "exit" as the value for my_input
. The loop will prompt the user to enter a value using the input()
function and will print out the value entered. If the value entered is "exit", the loop will exit and print "Loop exited".
You can modify this code according to your requirements.
Happy Coding!