Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
55 lines (38 loc) · 777 Bytes

File metadata and controls

executable file
·
55 lines (38 loc) · 777 Bytes
Copy raw file
Download raw file
Outline
Edit and raw actions

while

Examples in Python 3

"""
Loop until x is certain value
"""
x = 0
while x < 10:
	x += 3
	print(x)


"""
Loop until x is certain value with while True and break
"""
x = 0
while True:
	x += 3
	print(x)
	if x > 10:
		break


"""
More useful while with break (nothing to iterate over) - take input until input is "done"
"""
my_str = ""
while True:
	inp = input("> ")
	if inp == "done":
		break
	my_str += inp
print(my_str)

Reference and read more

The while statement

While loops

Revision history

2014-07-17 (sylvanas) PA1 First try.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.