Logic Flow: while loop

Beginning Python Programming

Makzan, 2020 April.

while loop

  • while condition
  • break
  • list append
  • joining list into string

Code example: while loop

while True:
    value = input("Please input a to-do task, or 'q' to quit: ")
    if value == "q":
        break

Code example: while loop

tasks = []

while True:
    value = input("Please input a to-do task, or 'q' to quit: ")
    if value == "q":
        break
    tasks.append(value)

print(tasks)

Code example: while loop

tasks = []

while True:
    value = input("Please input a to-do task, or 'q' to quit: ")
    if value == "q":
        break
    if len(value) > 0:
        tasks.append(value)

print(tasks)

Code example: while loop

tasks = []

while True:
    value = input("Please input a to-do task, or 'q' to quit: ")
    if value == "q":
        break
    tasks.append(value)

print(", ".join(tasks))

Code example: while loop

tasks = []

while True:
    value = input("Please input a to-do task, or 'q' to quit: ")
    if value == "q":
        break
    tasks.append(value)

print("\n".join(tasks))

while loop

  • while condition
  • break
  • list append
  • joining list into string

Summary