while
` loop :# Using the while loop
count = 0
while count < 5:
print("Count is", count)
count += 1
print("Done.")
Count is 0
Count is 1
Count is 2
Count is 3
Count is 4
Done.
while
` loop to repeat a block of code as long as a condition is true. The variable `count
` is initialized to `0
`. Then, we use the `while
` loop to repeat the block of code as long as `count
` is less than `5
`. count
` using the `print()
` function and increment the value of `count
` by `1
` using the `+=
` operator.count
` reaches `5
`, the loop exits, and the program continues to execute the `print()
` statement outside the loop, which prints the message "Done
."while
` loop to repeat a block of code as many times as needed, based on a condition.