I want to run 1 time ONLY in while loop.
while True:
print("Hello World")#this word always print
print("HI")#this word print 1 time only
I have no idea what your use case is... but just add a "break" to end the loop.
while True:
print("Hello World")
print("This words should show 1 time")
break
Edit based on your comment...
ran = False
while True:
print("Hello World")
If not ran
print("This words should show 1 time")
ran = True
Just add a validation logic to it
x = False
while True:
print("Hello World")
if x == False:
print("HI")
x = True
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.